Search between date & format error
Search between date & format error
m75sa
Posts: 132Questions: 30Answers: 0
Hi,
i followed the script to filter datatable results by date range.
Results date format is dd/mm/YYYY (i.e. 17/09/2022)
when i filter from the picker it doesn't work. it only works when i change the result date format in Y-m-d
Any ideas how to fix?
This question has accepted answers - jump to:
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi colin,
this is the test case:
live.datatables.net/fotabebi/1/edit
Had to make a couple changes to get your test case to run. Your Datatables code is looking for 3 columns with the date in the 3rd column. But your table has only one column.
If you do some debugging you will find that
var date = new Date( data[0] );
returns "Invalid Date". The Javascript Date() state the date is expected to by in ISO 8601 format. The ISO 8601 spec shows this as the formatYYYY-MM-DDTHH:mm:ss.sssZ
.One option is to use moment.js to convert the date format. See the updated example:
http://live.datatables.net/jobewaji/1/edit
Kevin
@kthorngren thanks a lot! This is what i needed.
@kthorngren i'm reopening your help on this example. If i want to use ajax server side processing, how will work the data filter?
The search plugins only work with client side processing. With server side processing enabled you will need to send the date input values to the server. You can use
ajax.data
as a function to get the values and send them as parameters in addition to the normal server side processing parameters. See this example. The server script will need to grab these values and apply them as part of rthe data query for the date range.Kevin
@kthorngren...i need your help, as ever...
What i've done is:
in the html:
in the js:
in the server side file:
but doesn't work...
where is the error?
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
I'm not familiar with PHP but I would guess that this is wrong:
You can do some debugging of what is sent in the request, ie look at the browser's network inspector for the XHR request parameters or in your PHP script, to see what parameters are recieved. But I believe you will want this:
To match the parameter you add to the request here:
If you look at the example I link to there is no return statement. Remove
return dtParms
.Kevin
thanks! I fixed thanks to your help.
@kthorngren
sorry... on the custom field i created (#min), when i set the savestate it doesn't save the status... how can i fix?
Since that is not a Datatables element but a custom element you created you will need to use
stateSaveParams
to add that value to the saved object. ThestateLoadParams
is used to get that saved object and restore it to the input value.Kevin