Skip to content

Instantly share code, notes, and snippets.

@wsakaren
Created June 21, 2014 16:18
Show Gist options
  • Save wsakaren/f8f8f73eafb9a49dd2bb to your computer and use it in GitHub Desktop.
Save wsakaren/f8f8f73eafb9a49dd2bb to your computer and use it in GitHub Desktop.
column sorting with datatables on checkbox
/* 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