I thought I was losing my mind for a minute there - I was sure there was two questions and then when I looked back there was only one! Just seen the edited tag...!
Have a peak at this thread which covers something similar to this. You'll need to use the API to get the DOM elements which you are sorting on, and then get their values to sort upon.
Another option is to add event listeners to each checkbox and change a value in a hidden column (you can use http://datatables.net/usage#iDataSort for this) or hidden element (with custom filtering).
However, here is an example which does live DOM sorting with checkboxes (or any other DOM element): http://datatables.net/examples/plug-ins/dom_sort.html
is there any way (e.g. http://datatables.net/examples/plug-ins/dom_sort.html ) to sort the checked first ?? you should click twice to see the checkboxed first...
In the function who is sorting the checkboxes, change this.checked == true to false ;)
Like this =>
[code]
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function(oSettings, iColumn) {
var aData = [];
$('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings)).each(function() {
aData.push(this.checked == false ? "1" : "0");
});
return aData;
}
I am also having the same problem sorting the check box column. I see the arrows moving, but there is no sort. Where and what coding do you put in the "Smoothness" theme?
Replies
Have a peak at this thread which covers something similar to this. You'll need to use the API to get the DOM elements which you are sorting on, and then get their values to sort upon.
Another option is to add event listeners to each checkbox and change a value in a hidden column (you can use http://datatables.net/usage#iDataSort for this) or hidden element (with custom filtering).
So many options :-)
Allan
What thread are you referring to? :)
I tried sorting checkbox columns expecting checked boxes to show on top (or bottom) but no luck. Any copy and paste stuff I can use?
However, here is an example which does live DOM sorting with checkboxes (or any other DOM element): http://datatables.net/examples/plug-ins/dom_sort.html
Allan
Love it, thanks Allan.
Expect to see an explosion in usage as there is a Drupal module coming your way :P
http://drupal.org/project/datatables
Regards,
Allan
In the function who is sorting the checkboxes, change this.checked == true to false ;)
Like this =>
[code]
/* Create an array with the values of all the checkboxes in a column */
$.fn.dataTableExt.afnSortData['dom-checkbox'] = function(oSettings, iColumn) {
var aData = [];
$('td:eq(' + iColumn + ') input', oSettings.oApi._fnGetTrNodes(oSettings)).each(function() {
aData.push(this.checked == false ? "1" : "0");
});
return aData;
}
[/code]