SearchBuilder date format
SearchBuilder date format
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
I suspect it is the fact you are using a customer rendering function that is tripping it up. It looks for the renderers built by
DataTables.datetime
and should automatically work with them.Are you able to give me a link to a test case or use https://live.datatables.net to create a test case so I can step through it please?
Allan
Hi Allan!
Thanks for your response.
We discussed the time zone problem with
DataTables.datetime()
a few weeks ago in https://datatables.net/forums/discussion/79973/time-zone-information-lost-when-using-datatable-render-datetime-docsAs for the live example, here you go:
https://live.datatables.net/katesico/1/edit
Thanks again.
@allan any ideas?
Anybody? I'm still stuck here
There you go:
https://live.datatables.net/katesico/3/edit?html,js,output
columns.searchBuilderType
Thanks a bunch! Not sure how I missed that.