How can I order by descending
How can I order by descending

I am creating the datatable using the code given below but the sorting order by desc is not working please hlep how to give the order the column //order: [[8, 'desc']],
table = $('#MeterArea').DataTable({
"processing": true,
"ajax": {
"type": "GET",
"url": url,
"datatype": "json",
"dataSrc": function (json) {
return JSON.parse(json);
}
},
"columns": [
{ "data":'Id'},
{ "data": 'DepotNo' },
{ "data": 'DepotName' },
{ "data": 'MeterCode' },
{ "data": 'ReadingYear' },
{ "data": 'ReadingMonth' },
{ "data": 'ReadingtxtDate' },
{ "data": 'Reading' }
{ "data": 'ReadingDate' }
],
//order: [[8, 'desc']],
"pageLength": 40,
scrollY: "400px",
scrollX: true,
paging: true,
dom: 'Bfrtip',
buttons: [
'copy',
'csv',
'excel',
{
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'LEGAL'
}
]
This question has an accepted answers - jump to answer
Answers
What you have
order: [[8, 'desc']],
is correct. I copied your statement here but changed the column number:http://live.datatables.net/cofihida/1/edit
Looks like that column might be a date (
ReadingDate
)? If the column is a date and not sorting correctly then follow the solution in the datetime sorting blog.If you still have difficulties we will need to see the problem. Post a link to your page or a test case replicating the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin