Sorting and highlighting dates (and strings)
Sorting and highlighting dates (and strings)
I’m trying to highlight the highest or lowest date values in a column based on an integer sorting version by @Colin. I’ve included the links to the dependancies and tried different combinations including wrapping the variable inside moment(var, "DD-MM-YYYY")
with no luck. I have successfully used moment.js before and use $.fn.dataTable.moment("DD-MM-YYYY");
but I’m not able to get the highest and lowest dates.
I would like to be able to sort dates and also A-Z strings if possible?
In the example below I can reverse the "a" and "b" and see the results as expected in column "A’ , but not column "B" {return b-a}
I would also like to find the highest or lowest date and not put the marker in the same cell which $(this.node())
does. I’d like to change the style of the name cell as an indicator instead?
This question has an accepted answers - jump to answer
Answers
If you're converting it to "DD-MM-YYYY", then "b-a" wouldn't make much sense there. It would be best to convert it to UNIX time (or epoch). That's an integer (seconds since 1970), which you can then use for your calculation,
Colin
Thanks @Colin. That was the advice I needed. I've updated the example and tried a-b and b-a which was successful. http://live.datatables.net/cokucuda/3/edit
Could you please make a change to the example so
this.node
has the correct code for putting the red cross at the side of the name?Use a
span
rather than adiv
: http://live.datatables.net/cokucuda/8/edit .The
span
is inline while thediv
is block display.Allan