how to sort by a column that has this format ?
how to sort by a column that has this format ?
mlotfi
Posts: 60Questions: 5Answers: 0
Hi,
I would like to display the table sorted by a column called createdAt that has this for mat :
2015-03-09T14:46:57.678-04:00
thanks, your help is appreciated.
This discussion has been closed.
Replies
https://datatables.net/blog/2014-12-18
I am not looking to format 2015-03-09T14:46:57.678-04:00 , I am looking for a way when the table displays it will be sorted by that column createdAT.
I added :
{
"aaSorting": [4, "desc"]
}
the sorting works fine, but the datatable is destroyed :
and I got this error :
DataTables warning (table id = 'inviteeListTable'): aTargets must be an array of targets, not a undefined
Uncaught TypeError: Cannot read property 'length' of undefined
Can you link to a test page showing the error please. Also, make sure you are using the latest version of DataTables. That error suggests you might be using a legacy version.
Allan
Here is a jsfiddle :
http://jsfiddle.net/mlotfi/qfmhmcw0/
the date format now is : 07/06/2015 04:37:32 PM EDT
You are using
aoColumnDefs
without atargets
option. SeecolumnDefs.targets
.Allan
even with the targets it does not work :
http://jsfiddle.net/qfmhmcw0/19/
I'm not sure why you put
aTargets
in its own object, the documentation I linked to doesn't show that. Put it in the object that you need to tell what column to apply to: http://jsfiddle.net/qfmhmcw0/20/ .Allan
Hi Allan,
if you take a look to the result of your jsfiddle, the column that has dates is not sorted in desc or asc,
No - but that is a different question :-). Your date string is not in a format that is supported by the
Date.parse()
Javascript method (which DataTables uses for date / time sorting).See this plug-in for how you can sort any data time format.
Allan