sort string that has number with -
sort string that has number with -
Hi I am new to datatable and I want to sort a column which has type as String that has number on it. Its sorting as String.
$(document).ready(function() {
$('#dashboard').DataTable({
"order": [[ 0, "desc" ]],
"lengthMenu" : [ [ 25, 50, 75, -1 ], [ 25, 50, 75, "All" ] ],
"pageLength" : 200,
"aoColumns": [ //When i changed the column type to num it sorts in beginning and after that-
{ "sType": "num" }, // -it does not sort.
null,
null,
null,
null,
null,
null,
null
]
});
});
Sample for my sorted column
AR-99
AR-983
AR-982
AR-981
AR-980
AR-98
AR-979
AR-978
AR-977
AR-976
AR-975
IR-99
IR-983
IR-982
IR-981
IR-980
IR-98
IR-979
IR-978
IR-977
IR-976
IR-975
....
....
I want the result as:
AR-983
AR-982
AR-981
AR-980
AR-979
AR-978
AR-977
AR-976
AR-975
...
...
IR-983
IR-982
IR-981
IR-980
IR-979
IR-978
IR-977
IR-976
IR-975
IR-974
Can any one help me with this please?
This question has an accepted answers - jump to answer
Answers
This is not the ideal solution, but you can provide a special value when the column is being sorted (see
columns.render
). Then you can split the "-" and format the number.I think the Natural sorting plugin might work. Here is a quick example using a subset of your data:
http://live.datatables.net/befahenu/1/edit
Kevin
Yes it worked with natural sorting plugin @kthorngren . Thank you @kthorngren @jvretamero for your suggestion.
Nice plugin @kthorngren!