SearchBuilder not working with moment or Luxon, so not able to format date filter

SearchBuilder not working with moment or Luxon, so not able to format date filter

HendrikdbHendrikdb Posts: 5Questions: 2Answers: 0

Link to test case:
https://jsfiddle.net/Hendrikdb/moa7e31L/6/
Debugger code (debug.datatables.net):

Error messages shown:
No error messages
Description of problem:

Hello,

After one day of trying to make it work, I still did not find a solution. The problem is that searchbuilder is not working with moment or luxon for date formatting in the conditions. I have tried every possible solution offered but I cant get it to work. I did a quick jsfiddle where you can see the problem.

What the issue is, is that when using the a datatable with column type date, it works but the format is YYYY-MM-DD. Changing format of datatable or changing the moment locale format does not work.

When using the exact example your site offers at link https://datatables.net/extensions/searchbuilder/examples/initialisation/date-fmt.html, the issue gets even worse, as you can see in the screenshot.

I do not see a date option (the div is hidden) but even if I try to select anything, I get a weird format. You can see that I was able to reproduce this easily in jsfiddle and many people are having the same problem.

trying the Luxon approach says that $.fn.dataTable.luxon( 'EEE, MMMM d, yyyy' ); the luxon is undefined. But I would like to fix moment and not use luxon.

Please advice on a fix for this bug.

I am having the same problem as the links below (all with a working example):

https://stackoverflow.com/questions/71894104/the-datatables-searchbuilder-encounters-bug-when-i-use-moment-js-implemented-by

https://peaku.co/questions/72924-el-generador-de-busqueda-de-datatables-encuentra-un-error-cuando-uso-momentjs-(implementado-por-el-paquete-yajra)

https://datatables.net/forums/discussion/68231/datetime-formatting-doesnt-work-with-searchbuilder

Answers

  • HendrikdbHendrikdb Posts: 5Questions: 2Answers: 0

    https://jsfiddle.net/Hendrikdb/moa7e31L/27/ this is a more simplified jsfiddle. Help is much appreciated :smile:

  • mtdevmtdev Posts: 13Questions: 2Answers: 1

    In your simplified jsfiddle, if you add a $.fn.dataTable.moment( 'DD/MM/YYYY' ); and remove your type: "moment", that should work (auto-detection).

  • mtdevmtdev Posts: 13Questions: 2Answers: 1
    edited July 27

    Or, if you want to force the format for a given column, you can use type: "moment-DD/MM/YYYY", explicitly.

    (but I have read that it is not recommended, even if I use it recently)

  • HendrikdbHendrikdb Posts: 5Questions: 2Answers: 0

    Hello,

    thanks for the fast response, with your help it seems to work as expected. Thank you very much for your assistance!

    have a nice day.

Sign In or Register to comment.