How to display Bootstrap Toggle switch using DataTables via Render

I use Bootstrap Toggle , CSS and JavaScript loads fine, see image. However, when I use the built-in datatable (Done coloumn) custom JavaScript and styling does not work. I get data through Ajax

Datatable script

$('#sampleTable').DataTable( { "ajax": { "url": "/generalTodo", "dataSrc": "" }, "columns": [ { "sortable": true, className: 'centerize', render: function ( data, type, full, meta ) { return '<input type="checkbox" checked data-toggle="toggle" data-on="Ready" data-off="Not Ready" data-onstyle="success" data-offstyle="danger">'; } },..... 

enter image description here

+5
source share
1 answer

I found a solution:

 return '<input id="toggle-demo" type="checkbox" checked data-toggle="toggle" data-on="Ready" data-off="Not Ready" data-onstyle="success" data-offstyle="danger">'; 

and

 "fnDrawCallback": function() { $('#toggle-demo').bootstrapToggle(); }, 

Downloading Js after the table completes the download!

+5
source

Source: https://habr.com/ru/post/1239244/


All Articles