Created
June 21, 2014 16:18
-
-
Save birchestx/f8f8f73eafb9a49dd2bb 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
/* 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'; | |
} ); | |
} | |
$('.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