https://datatables.net/blog/2014-12-18

https://datatables.net/blog/2014-12-18

offir.peeroffir.peer Posts: 9Questions: 4Answers: 0

I am using https://datatables.net/blog/2014-12-18 plugin to sort 3 different types of tables that in every one of them there is a different moment date format.

I saw that I need to push the formats before the tables are built like this:
$.fn.dataTable.moment('DD/MM/YY HH:mm');
$.fn.dataTable.moment('DD/MM/YYYY');

But the problem is that this is too general and so a table with a date format of 'DD/MM/YYYY' checks
this format 'DD/MM/YY HH:mm' as well.

What can I do so only certain tables will know their date format?

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    The date matching should be strict. If the data doesn't match the format DD/MM/YY HH:mm it shouldn't be used.

    Could you link to the page showing the issue please.

    It should be quite possible to use the $.fn.dataTable.moment method multiple times to define multiple formats and use them all on the same page.

    Might also be worth using the latest version of the code rather than that from the blog (I can't remember if there are any differences!).

    Allan

  • offir.peeroffir.peer Posts: 9Questions: 4Answers: 0

    Hi Allan,
    I was already using the latest version + added some modification of my own to it, for example when I don't have a date in a certain column I add "-" to the condition to get
    -inifinity.

    But let's say I have 2 different tables and each of them has a different date format, I
    add $.fn.dataTable.moment('DD/MM/YY HH:mm');
    before $("#firstFormat").DataTable() and "firstFormat" table will check only for 'DD/MM/YY HH:mm' format which is fine by me, but the problem is when I get to the second table init:

    $.fn.dataTable.moment('DD/MM/YY');
    $("#secondFormat").DataTable(); // this will check for columns with the format 'DD/MM/YY' and also the format 'DD/MM/YY HH:mm' , when I want it only to check for 'DD/MM/YY' format.

    Do you understand the problem I presented here?

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    What's the problem with it checking the first format in the second table? It will fail the type detection and thus not use the first format in the second table.

    Allan

  • offir.peeroffir.peer Posts: 9Questions: 4Answers: 0

    It's a redundant check, performance like.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Have you profiled it? I would be very surprised if that took a significant amount of time (or indeed more than a milli-second or two). I would be happy to take a look at your page if you give me a link to it.

    Allan

This discussion has been closed.