i have datatable and i want to sort in as numeric it contains value like 1st,2nd...., here is my code when i sort it it sorts values like 1st,10th,2nd so on how to sort it p
The simplest way I know of to do this is to use the Formatted Numbers plugin
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"formatted-num-pre": function ( a ) {
a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
return parseFloat( a );
},
"formatted-num-asc": function ( a, b ) {
return a - b;
},
"formatted-num-desc": function ( a, b ) {
return b - a;
}
} );
$('#tbl_jaar').dataTable( {
columnDefs: [
{ type: 'formatted-num', targets: 0 }
]
} );
Places
1st
2nd
3rd
4th
5th
6th
7th
8th
9th
10th