Reverse the order of a sort using DataTables
I have a column that has value "n/a" (without quotes) and numbers from 0 - 5, when sorted it shows 0 first and开发者_C百科 the other way shows n/a first and begins descending, is there a way to make it show n/a and then ascend to 5? I have tried:
oTable.fnSort([[0, 'natural-asc']]);
and
"aaSorting": [[ 0, "natural-asc" ]],
but no luck. Also, is there a way to have it behave correctly when using a special character like $ or €? because so far I haven't been able to make it do so either.
If you want to apply a different sorting type you should use aoColumns like this:
"aoColumns": [
null,
null,
null,
{ "sType": "natural" },
null
]
To use natural sorting you should do the following things:
- include the function for the natural sorting from this page
define your own sorting function like this:
jQuery.fn.dataTableExt.oSort['natural-asc'] = function(a,b) { return naturalSort(a,b); };
jQuery.fn.dataTableExt.oSort['natural-desc'] = function(a,b) { return naturalSort(a,b) * -1; };
- use aoColumns like indicated above
-in any case if you post an example on jsfiddle.net it's easier to help
精彩评论