Checkbox data source
Sort based on the checked state of checkboxes in a column
- Author: Allan Jardine
Read information from a column of checkboxes (input elements with type checkbox) and return an array to use as a basis for sorting.
Plug-in code
$.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';
} );
};
CDN
This plug-in is available on the DataTables CDN:
Note that if you are using multiple plug-ins, it is beneficial in terms of performance to combine the plug-ins into a single file and host it on your own server, rather than making multiple requests to the DataTables CDN.
Version control
If you have any ideas for how this plug-in can be improved, or spot anything that is in error, it is available on GitHub and pull requests are very welcome!
- This plug-in: dom-checkbox.js
- Full DataTables plug-ins repository: DataTables/Plugins