Server-side processing how to handle date searches.

Server-side processing how to handle date searches.

GlyndwrGlyndwr Posts: 117Questions: 32Answers: 0

http://live.datatables.net/idinat/edit

When searching in server-side processing the search starts with the first character entered and continues for each character entered. So what is the recommended way to handle searching for a date with format dd/mm/yyyy? I suppose we assume that any number followed by a '/' is a date and convert it to '-'. As dates are stored as yyyy-mm-dd then we would:
* 2 [search for 2]
* 2/ [ search for -2]
* 22/ [search for -22]
* 22/3 [search for 03-22]
* 22/12 [search for 12-22]
* 22/12/2 [ search for 2-12-22]
* etc

Is there a really smart way of doing this?

Kind regards,

Glyn

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    The best way of doing this would be to present the end user with a date picker calandar input and then base the search on that. Reject anything from the input that cannot be strictly parsed using the date format you are allowing.

    Allan

  • GlyndwrGlyndwr Posts: 117Questions: 32Answers: 0

    Thanks Allan,

    How do I do that with the "Search:" field (i.e., curently the search is entered into the "Search:" field, and I do not want to loose that, so how do we combine the "Search:" with a date field)?

    We would need to be able to do both a date search and a text search.

    How would this allow us to search for everyone, say, born in 2000?

    With the original I can enter "John 2000" and it will filter accordingly.

    Kind regards,

    Glyn

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,735

    combine the "Search:" with a date field)?

    If you use a date picker as Allan suggested then use column().search() for the date column. That and the global search will both be sent to the server. Take a look at the server side docs for info regarding the parameters sent.

    Kevin

This discussion has been closed.