different iDataSort for sorting ascending and descending
different iDataSort for sorting ascending and descending
Is there any way to specity two iDataSort, for ascending and descending (on the same column, ofcourse)?
This discussion has been closed.
Replies
[code]
"aoColumnDefs": [
{ "iDataSort": 1 asc, "aTargets": [ 0 ] } ,
{ "iDataSort": 2 desc, "aTargets": [ 0 ] }
]
[/code]
1. Detach the sorting listener DataTables puts on the header element and then attach your own which will call fnSort with the sorting information you require.
2. Define a sorting plug-in with a different 'asc' from 'desc' algorithm.
I've not seen this done before I must admit, so its not something I've tried to do in DataTables, but the above methods (possibly with a bit more work?) should make it possible.
Allan
It would be nice if I can implement point 2, but I think I'll end up with the same problem? i.e., I have access to the values of one column, and not the other?
so if I have: { "iDataSort": 1 , "aTargets": [ 0 ] }
[code]
jQuery.fn.dataTableExt.oSort['pc-asc'] = function(a,b) {
/*this is fine as I want to sort on column 1 for asc*/
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};
jQuery.fn.dataTableExt.oSort['pc-desc'] = function(a,b) {
/* I don't have access to column 2, so how do I sort using column 2 (for desc)*/
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
[/code]