Error using moment.js with date format DD/MM/YYYY

Error using moment.js with date format DD/MM/YYYY

cj1005cj1005 Posts: 142Questions: 45Answers: 1

Hi,

I'm trying to get SearchBuilder working with our date columns using moment.js & I've got the columns sorting correctly and the SearchBuilder recognizes the date column as a date field, but when I click on the required 'Condition' within the SearchBuilder popup screen, I get the console error message below and the 'Value' pull-down is blank and non-responsive:

"dataTables.dateTime.min.js:13 Uncaught DateTime: Without momentjs, dayjs or luxon only the format 'YYYY-MM-DD' can be
used"

I tried removing the 'dataTables.dateTime.min.js' & 'dataTables.dateTime.min.css' as I thought these may be clashing with moment.js, but I get the following error:

"dataTables.searchBuilder.min.js:22 Uncaught DateTime: Without momentjs or dayjs only the format 'YYYY-MM-DD' can be used"

You can see the test case, by going to:

https://www.wd4g.com/WCGateway/WDLogin.wc

Login with: DTUSERS (same for un & ps)

Then, click on 'Test' from the navbar.

Any help greatly appreciated.

Regards, Chris

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736
    Answer ✓

    Seems like the issue is with a conflict between SearchBuilder and the datetime-moment.js sorting plugin. I simplified your example:
    http://live.datatables.net/timilitu/1/edit

    Comment out $.fn.dataTable.moment('DD/MM/YYYY'); and the SearchBuilder search works without the error. @allan or @sandy will need to take a look.

    Kevin

  • cj1005cj1005 Posts: 142Questions: 45Answers: 1

    Hi Kevin,

    Thank you for simplifying the example, that has really helped as using that I have found the issue:

    I moved the 'dataTables.searchBuilder.min.js' CDN to after the 'moment.min.js' & 'datetime-moment.js' CDN's and it worked :smile:

    Would never have tried that without your example, so thank you so much!

    Chris

  • kthorngrenkthorngren Posts: 20,142Questions: 26Answers: 4,736

    Interesting. I did try moving moment.js before both searchBuilder.js and datetime-moment.js but go the same error. Sounds like there is an order importance with searchBuilder.js and datetime-moment.js too.

    Kevin

This discussion has been closed.