Sort by year-number
Sort by year-number

HI i have a table with a culumn formed as year-number .
For example 2024-55
The problem is when i have 2024-6 datatable sort 2024-6 before 2024-55 in desc mode
How can i solve ?
HI i have a table with a culumn formed as year-number .
For example 2024-55
The problem is when i have 2024-6 datatable sort 2024-6 before 2024-55 in desc mode
How can i solve ?
Answers
The natural sorting plugin might do the job for you here.
Allan
Hi , i try to use natural sort :
[CODE]
$("#tabella-catalogo").DataTable({
columnDefs: [{
type: 'natural',
target: 2
}],
order: [
[2, 'desc'],
],
keys: true,
responsive: true,
select: true,
"language": {
"sEmptyTable": "Nessun dato presente nella tabella",
"sInfo": "Vista da START a END di TOTAL Record",
"sInfoEmpty": "Vista da 0 a 0 di 0 Record",
"sInfoFiltered": "(filtrati da MAX Record totali)",
"sInfoPostFix": "",
"sInfoThousands": ".",
"sLengthMenu": "Mostra MENU Record",
"sLoadingRecords": "Caricamento...",
"sProcessing": "Elaborazione...",
"sSearch": "Cerca:",
"sZeroRecords": "Nessun risultato.",
"oPaginate": {
"sFirst": "Inizio",
"sPrevious": "Precedente",
"sNext": "Successivo",
"sLast": "Fine"
},
"paginate": {
"previous": "<i class='fas fa-arrow-left'></i>",
"next": "<i class='fas fa-arrow-right'></i>"
}
},
"drawCallback": function() {
$(".dataTables_paginate > .pagination").addClass("pagination-rounded");
}
});
[/CODE]
but doesn't work :
Did you load the plugin code?
I built a simple test case with a sample of your data and it seems to work:
https://live.datatables.net/wuhemamo/1/edit
If you still need help then please update my test case to show the issue or provide a link to your page so we can take a look.
Kevin
This is my source view :
But doesn't work properly
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
The code snippet is not enough to help us debug. The problem is likely due to something in your data. Can you update my test case to show the issue or provide a link to your page so we can see why the plugin doesn't work with your data.
Kevin
Does that column have HTML wrappaing the numeric data? If so maybe you need to use
natural-nohtml
instead. See th eplugin docs for details.Kevin