render date and retain order functionality (ajax object)
render date and retain order functionality (ajax object)
I am using datatables 1.10 with an ajax datasource and am struggling with the syntax for rendering then ordering the json data , specifically date values
My raw date data is in the form 2015-12-10 11:30:00 and my date column is displayed properly and sorts properly.
Using examples from the site as a guide, I have the following code snippet to render the date column, which uses the jquery-dateFormat.min.js to format the date values
{
"render": function ( data, type, row )
var rowvalue = row["EventDate"];
return ($.format.date(rowvalue, "E dd/MM/yyyy"));
},
"targets": 2
},
This works, and the dates are displayed as I want them but the sorting no longer works
On earlier incarnations of datatables, I used 2 instances of the date column - hid one of them and formatted the other. I then applied the sort to the hidden column when clicking on the column header of the visible one.
From what I understand, I can use the render function to change the display, but also use it to sort by the original form.
I tried following the example on http://datatables.net/manual/orthogonal-data#Computed-values But can’t get it to work.
Would appreciate some pointers.
a cut down work in progress page here... http://test2.forthwebsolutions.com
Thanks
This question has an accepted answers - jump to answer
Answers
Since the original post, I have tried to implement the moment.js plugin. - but the sorting still doesnt work properly.
I am using a date from a mysql table, in the format YYYY-MM-DD
i then render this value using moment to format the raw date
in my js, before the table script, i add
but the dates do not sort correctly - the column is always sorted as if was alphanumeric
Fixed it
I revisited http://datatables.net/manual/orthogonal-data#Computed-values and having read through it again, I used moment to format my sql formatted date for display and left it as for sorting.
I also used a boolean variable rowvalueallday to format the date with a time where required
Hi,
Sorry I missed your thread before - but great to hear that you have a solution for the problem now!
Allan