Reputation: 23989
I'm using JQuery datatables plugin and works really well. Problem I have is sorting a date field. The date field is the first field in the table.
For a better UX (because day of the week is an important factor) I want to show dates in ascending order like this:
Fri 4th July 2014
Thu 10th July 2014
Fri 18th July 2014
When I load the table into datatables
it sort the field thus:
Fri 18th July 2014
Fri 4th July 2014
Thu 10th July 2014
Which is alpha numeric. Not good for dates.
Is there any way I can add a field to the <td>
e.g. <td data-sort="2014-05-06">
and have it sort according to that variable instead of just the cell contents for that particular column?
I have searched their docs and API but can't see an immediate solution.
Upvotes: 0
Views: 83
Reputation: 23989
The answer is actually in my question... I guessed what the solution should be without trying it as I couldn't find any reference to it.
tl;dr
<td data-sort="2014-05-06">
Many thanks @TamilSelvan
You can also use timestamp as suggested below
Upvotes: 1
Reputation: 20209
Use data-order=(date in timestamp format)
<td data-order="1332975600">Thu 29th Mar 12</td>
Refer: http://datatables.net/examples/advanced_init/html5-data-attributes.html
Upvotes: 1