I have a datatable which has checkboxes in first td
some are coming checked while some are unchecked from database
by default it is not sorting checked/unchecked, so I also added data-sort attribute
now sort is working as per data-sort values on page load
but I want when checkbox is changed the data-sort should also be changed so that it sort correctly. I did below it is changing data-sort in dom but I think not in datatable.
var dt3;
$(function(){
dt3 = $('.dt3').DataTable();
$('body').on('change','input.chkV1',function(){
var sortVal = $(this).is(':checked')?1:0;
// $(this).parents('td').attr('data-sort',sortVal);
// $(this).parents('td').data('sort',sortVal);
$(this).parents('td').data('sort',sortVal).attr('data-sort',sortVal);
dt3.draw();
});
});
I think dt3.draw(); only update cell data not attributes
Actually in datatables docs you could find the solutions but i have made one for your. But if you want to check also here the link.
Bu i have made a sample for you to see all the details. Simple you add to DataTables extension a new sorting method. And then when you user $('#table').DataTable method you use columns and define your method if you use null as denination you can use default settings