0
Guys, I have the following columns in my table, and one of them is the "Month" it gets an int that refers to the number of the month (1 - Jan, 2 - Feb, etc.) When the screen loads the table displays the months in the right order but if I click to order, it sorts in alphabetical order, how do I sort by the sequence of months?
var colsCurrency = [
{ data: 'Year', orderable: true, className: 'col-sm-2 text-center', title: 'Year' },
{
data: 'Month', orderable: true, className: 'col-sm-2 text-center', title: 'Month', render: function (data) {
month = data;
switch (month) {
case 1:
colMonth = "January";
break;
case 2:
colMonth = "February";
break;
case 3:
colMonth = "March";
break;
case 4:
colMonth = "April";
break;
case 5:
colMonth = "May";
break;
case 6:
colMonth = "June";
break;
case 7:
colMonth = "July";
break;
case 8:
colMonth = "August";
break;
case 9:
colMonth = "September";
break;
case 10:
colMonth = "October";
break;
case 11:
colMonth = "November";
break;
case 12:
colMonth = "December";
break;
}
return colMonth;
}
},
{ data: 'Name', orderable: true, className: 'col-sm-2 text-center', title: 'Type' },
{
data: 'ValueUsTax', orderable: true, className: 'col-sm-2 text-center', title: 'Tx Dollar', render: function(data, type, full) {
return parseFloat(data).toFixed(4);
}},
{
data: 'ValueCcyFactor', orderable: true, className: 'col-sm-2 text-center', title: 'CCY Factor', render: function (data, type, full) {
return parseFloat(data).toFixed(4);
}
},
{
data: null, orderable: false, className: 'text-center col-sm-1', title: 'Actions', render: function (data, type, full) {
if (data.ActiveFlag) {
var retorno = '<nobr><button type="button" class="btn btn-xs btn-default" title="Edit" onclick="EditCurrencyById(' + full.CurrencyId + ')"><i class="glyphicon glyphicon-pencil"></i></button> ';
retorno += '<button type="button" class="btn btn-xs btn-danger" title="Delete" onclick="DeleteCurrency(' + full.CurrencyId + ')"><i class="glyphicon glyphicon-remove"></i></button></nobr>';
return retorno;
}
else {
var retorno = '<button type="button" class="btn btn-xs btn-primary" title="Active" onclick="Active(' + full.CurrencyId + ')"><i class="glyphicon glyphicon-off"></i></button></nobr>';
return retorno;
}
}
}
];
Try using this here:
$('#idDaTabela').DataTable( {
 "order": [[ 2, "asc" ]]
 } );
Fountain here– adventistaam
It did not work ,when I order it still orders by alphabetical order
– Dan Oliveira
You can insert the column with the month number and hide using the
display: none
in the cell and you can use the function I sent referencing the column’s input– adventistaam