My mission is to appear toggle JavaScript in my DataTables but it seems not function not only the button even the functions.
Here is my Code
HTML
<div class="col-lg-12 col-md-12 col-sm-12 mb-30">
<table class="data-table stripe hover multiple-select-row nowrap" id="example">
<thead>
<tr>
<th class="table-plus datatable-nosort">No</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td class="table-plus">1</td>
<td>Michael</td>
<td>123456789</td>
<td>[email protected]</td>
</tr>
</tbody>
</table>
</div>
</div>
JS
<script>
$(function(){
$.fn.bootstrapSwitch.defaults.onColor = 'success';
$.fn.bootstrapSwitch.defaults.offColor = 'danger';
$.fn.bootstrapSwitch.defaults.size = 'mini';
$.fn.bootstrapSwitch.defaults.state = 'false';
$.fn.bootstrapSwitch.defaults.inverse = 'true';
$(".toggle-vis").bootstrapSwitch();
var table = $('#example').DataTable();
$('.toggle-vis').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var column = table.column($(this).attr('data-column'));
column.visible( ! column.visible() );
});
});
</script>
I am trying to replicate someones code here JSFiddle unfortunately the toggle is not appear.
</tbody>tbody>or is it actually in your code? Cause that might be the problem.bootstrapSwitch. have you defined it somewhere?