Sort by column number when there is a letter after the number to sort by
Sort by column number when there is a letter after the number to sort by
Link to test case: https://bigwebuy.com/flora/colecciones - Click on "Buscar"
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: I'd like to sort the items in "N° Col" column by number, but the numbers have a suffix letter sometimes (separated by a space) and therefore it's sorting the items alphabetically. Ideally, it would sort it like this:
1
2
3
10 A
11 A
...
But currently it's sorting like this:
1
10 A
11 A
2
3
...
This question has accepted answers - jump to:
Answers
Try the Natural Sorting plugin.
Kevin
Thanks a lot Kevin, this indeed solved the issue!
I added this to the options when initializing the Datatable
columnDefs: [
{ type: 'natural', targets: '_all' }
],
Note the '_all' instead of 0 which is what the Datatables official documentation suggests.
Many thanks lovely community !
Using
targets: '_all'
may affect sorting of other columns. If so then setcolumnDefs.targets
to target only those that need the natural sorting plugin.Kevin