Date Sorting in Datatable Editor Join Table

Date Sorting in Datatable Editor Join Table

a2ztecha2ztech Posts: 19Questions: 2Answers: 1

I used moment.js to sort my StartTime and EndTime columns and it works perfect.

As seen in the attached image I have Date Select Control (Editor Join Table: derived from this example - https://editor.datatables.net/examples/inline-editing/join.html).

I could NOT get the date sorted correctly in the Select control (I tried adding the Order clause in the .NET controller as well as adding $.fn.dataTable.moment( 'ddd, MMM dd, yyyy') in my HTML but does NOT help.

Can somebody please help me with way to approach this?

Thanks!

Replies

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Hi,

    The best way to sort formatted date / time columns, particularly if you already have Moment.JS on your page, is to use the plug-in introduced in this blog post. Basically you tell it the format you want and it will automatically detect and sort such columns.

    Regards,
    Allan

  • a2ztecha2ztech Posts: 19Questions: 2Answers: 1
    edited September 2016

    @allan - thanks for your reply.

    It seems that the plug-in does not work on the join table. My earlier attachment shows a drop-down list with some dates in it. I would like to have these dates sorted but even after adding $.fn.dataTable.moment( 'ddd, MMM dd, yyyy') to my JavaScript it does not.

    Really appreciate if we know a way out?

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    I see - yes, the plug-in operates on the data in a column. Not in a drop down list.

    Where are you getting those values from? Are they from the Field->options() method in Editor, or something else? If something else, then you need to modify whatever that is to sort them correctly. If it is coming from Editor's PHP or .NET libraries, then I'm afraid that's a limitation at the moment - it will always string sort the options. Custom sorting is something I plan to introduce in 1.6.

    Allan

  • a2ztecha2ztech Posts: 19Questions: 2Answers: 1

    thanks @allan - yes, it is Field->options(). We will look forward to having this feature in 1.6.

This discussion has been closed.