Sorting and highlighting dates (and strings)

Sorting and highlighting dates (and strings)

silkspinsilkspin Posts: 141Questions: 32Answers: 5

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?

http://live.datatables.net/cokucuda/1/edit

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,163Questions: 1Answers: 2,588
    Answer ✓

    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

  • silkspinsilkspin Posts: 141Questions: 32Answers: 5

    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?

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    Use a span rather than a div: http://live.datatables.net/cokucuda/8/edit .

    The span is inline while the div is block display.

    Allan

This discussion has been closed.