DataTables date sorting issue
DataTables date sorting issue
cbarrett
Posts: 9Questions: 2Answers: 1
I have a json that I call and parse: JSON
The JSON returns a date/time in epoch. I convert the epoch using the following method:
var d = new Date(forecastFeatures[i].attributes.FORECAST_HOUR);
var forecastHour = d.toUTCString();
var dateString = forecastHour;
dateString = dateString.split(' ').slice(0, 5).join(' ')
This returns me the following: Fri, 07 Jul 2017 02:00:00
That is the exact format I want. I do a console.log to view the forecast hours and the forecast hour returns in ascending order. Datatables is not sorting the data based on the return of the JSON call.
function renderDataTable() {
$('#forecast-table').DataTable({
destroy: true,
searching: false,
scrollX: false,
scrollY: "400px",
scrollCollapse: false,
paging: false,
responsive: true,
info: false,
autoWidth: true,
footer: false
});
}
How do I sort a datatable based on the order the JSON returns?
This discussion has been closed.
Answers
Many people use the plugn described in this blog for date time sorting:
https://datatables.net/blog/2014-12-18
Maybe it will work for you.
Kevin
@kthorngren thank for you the reference! I was able to perform a work-around.
So that the DataTable sorts based on the month, then day, then time.