-
-
Save RedhatPH8/6d608f25ef84f54dee02ac586dcfc070 to your computer and use it in GitHub Desktop.
column sorting with datatables on checkbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**LEGACY DataTables 1.9 | |
/* Create an array with the values of all the checkboxes in a column */ | |
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function ( oSettings, iColumn ) | |
{ | |
return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) { | |
return $('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0'; | |
} ); | |
} | |
*// | |
/**Updated to DataTables 1.10**/ | |
/* Create an array with the values of all the checkboxes in a column */ | |
$.fn.dataTable.ext.order['dom-checkbox'] = function ( settings, col ) | |
{ | |
return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) { | |
return $('input', td).prop('checked') ? '1' : '0'; | |
} ); | |
} | |
$('.ratemgr-table').dataTable({ | |
"aoColumnDefs": [ | |
{ "bSortable": false, "aTargets": [ "action" ] }, | |
{ "sSortDataType": "dom-checkbox", "aTargets": [ "enabled" ] } | |
], | |
"aaSorting": [ | |
[ 3, "desc" ] | |
] | |
}); | |
In the view I have this to enable me to put the checkbox in different columns (not tied to col number): | |
<th class="enabled">Enabled</th> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment