Hi,
thanks for your post, and sorry for the trouble.
There is indeed no direct natural sorting algorithm in the DataTables JS library. However, normally the columns in your table can be made to sort correctly – if you properly move that second row with the descriptions to the table’s header row (which now has the 1, 2, 3, 4, 5). Otherwise, these texts will be included in the sorting and they will be moved with the other rows.
In addition, to fix a small visual bug, could you please try adding this to the “Custom CSS” textarea on the “Plugin Options” screen of TablePress:
.tablepress {
border-collapse: separate;
}
Regards,
Tobias
Hi Tobias,
The table is correct when the page is loaded.
The problem occurred when trying to sort from most column.
Order turn to 1, 10, 100, 2 instead of 1, 2, 10, 100.
I used JSGrid before. You should try it.
Or there is a natural sort plug-in for datatables here:
https://datatables.net/plug-ins/sorting/natural
Regards
Yves
Hi Tobias,
Sorry, the problem is not natural sorting.
It doesn’t recognize the international metric writing of “1 000” instead of “1000” in my last column.
The regex needs to remove the space between numbers.
Regards
Yves
Hi,
to now use a proper sorting algorithm, please add this to the “Custom Commands” text field on the “Edit” screen of the table:
"columnDefs": [ { "type": "num-fmt", "targets": [ "_all" ] } ], "language": jQuery.extend( {}, DataTables_language["fr_FR"], { "thousands": " " } )
Regards,
Tobias
Hi Tobias,
Thanks, work better now but only ascendant.
Descendant still not sorting thousand properly.
Regards
Yves
Hi Yves,
it could be possible that the external DataTables JS library wants a different character for the thousand delimiter. Could you maybe try a .
?
Regards,
Tobias
Hi Tobias,
Doesn’t work
Dot would not be international metric system.
Regards
Yves
Hi Tobias,
The question was asked before here:
https://datatables.net/forums/discussion/10113
The plug-in is here:
https://datatables.net/plug-ins/sorting/formatted-numbers
But deprecated because suppose to be in Datatable.
But the regex removed a “-”
What I need is to remove a space not a – so the code should be:
” ”
Like that:
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;
}
} );
Regards
Yves
-
This reply was modified 6 years, 2 months ago by
qualitas.
-
This reply was modified 6 years, 2 months ago by
qualitas.
Hi Tobias,
I found a solution here:
https://datatables.net/forums/discussion/20853
by just adding HTML code  
instead of space is working.
Regards
Yves
-
This reply was modified 6 years, 2 months ago by
qualitas.
Hi,
you could maybe check out the TablePress Extension from https://tablepress.org/extensions/datatables-sorting-plugins/
This adds some extra sorting algorithms via the included JavaScript files (non-minified and minified!). This also has a formatted-num
algorithm. You could either try that or modify it to your needs.
Regards,
Tobias