Home Use bootstrap switch in Ajax datatable
Reply: 0

Use bootstrap switch in Ajax datatable

user2492
1#
user2492 Published in April 19, 2018, 10:02 am

I have metronic template and I use metronic datatable like this:

var DataTablePerfiles = function () {
  //== Private functions
  var token = JSON.parse(localStorage.getItem('currentUser')).token;
  // basic demo
  var getList = function () {
    var datatable = $('.m_datatable').mDatatable({
      // datasource definition
      data: {
        type: 'remote',
        source: {
          read: {
            // sample GET method
            method: 'GET',
            headers: {
              'Authorization': 'Bearer ' + token,
            },
            url: 'http://myapiurl',
            map: function (raw) {
              // sample data mapping
              var dataSet = raw;
              if (typeof raw.data !== 'undefined') {
                dataSet = raw.data;
              }
              return dataSet;
            },
          },
        },
        pageSize: 10,
        serverPaging: false,
        serverFiltering: false,
        serverSorting: false,
      },
      // layout definition
      layout: {
        theme: 'default', // datatable theme
        class: '', // custom wrapper class
        scroll: false, // enable/disable datatable scroll both horizontal and vertical when needed.
        footer: false // display/hide footer
      },

      // column sorting
      sortable: true,
      pagination: true,

      search: {
        // enable trigger search by keyup enter
        onEnter: false,
        // input text for search
        input: $('#generalSearch'),
        // search delay in milliseconds
        delay: 400,
      },

      // columns definition
      columns: [
        {
          field: "activo",
          title: "Activo",
          sortable: true,
          template: function (row, index, datatable) {
            return '<input data-switch="true" type="checkbox" checked="checked" id="m_switch_1">';
          }

        }
      ]
    });
  };

As you can see in columns I want to use bootstrap switch like this link but for some reason it just don´t work and don´t show any errors

Bootstrap switch code on column:

  template: function (row, index, datatable) {
                return '<input data-switch="true" type="checkbox" checked="checked" id="m_switch_1">';
              }

Some one knows what am I doing wrong there? how can I show up Basic Example of bootstrap switch depending of value recived (true or false). Regards

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.526398 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO