SearchBuilder date format

SearchBuilder date format

kc5151kc5151 Posts: 58Questions: 7Answers: 1

Hi,

feeling a bit dumb again since I guess this should be easy to solve, but I cannot seem to find the correct solution.

I'm displaying dates in my Datatable using a custom render function.

When I search for date columns using SearchBuilder, it uses the YYYY-MM-DD format. Which is not what my Datatable is using, so it doesn't work.

In the docs, I found:

https://datatables.net/extensions/searchbuilder/examples/initialisation/date-fmt.html

There is says, I'm supposed to use:

DataTable.datetime('HH:mm MMM D, YY');
DataTable.datetime('ddd, MMMM Do, YYYY');

(or whatever date format I need). How does that relate to my render function? Am I supposed to remove the render function? Also, I don't use DataTable.datetime() in my render function since it has time zone issues. Instead, I did something like this:

    DataTable.render.mydatetime = function (fmt) {
      return function (data, type, row) {
        if (type === 'type' || type === 'sort') {
          if (data == null) {
            return null;
          }
          return data.startsWith('0000-00-00') ? null : data;
        }
        return data == null ? null : moment(data).format(fmt);
      };
    };

and in my render function I'm calling DataTable.render.mydatetime('DD.MM.YYYY'); or DataTable.render.mydatetime('DD.MM.YYYY HH:mm:ss') depending on my needs.

So, what I basically need is an option for the SearchBuilder to use the date format from the render function.

Thanks a bunch in advance.

This question has an accepted answers - jump to answer

Answers

Sign In or Register to comment.