SearchBuilder : unexpected order of values (1 and 2) with "[!]between" and server-side
SearchBuilder : unexpected order of values (1 and 2) with "[!]between" and server-side
Link to test case: https://editor.datatables.net/examples/extensions/searchBuilder.html
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Hello,
When using server-side and a "between" (or "!between") condition on a filter with a date type, data sent to the server are not ordered as filled (input HTML element), if only one input has been filled.
The server-side request is triggered, but the result does not take into account the inputted date (1st or 2nd field), so that does not create an issue with the server-side script you provide, I guess, but if we custom the server-side implementation, that would be great to distinct the 1st and 2nd field. More explanation on the last points of this post : "A use case / To go further"
Steps to reproduce
Case 1) only 1st date : KO
1) Click on "Add condition", select the data Start date, select the condition Between
2) Input 2012-12-02 in the 1st field and let the 2nd one empty
3) Check the server side AJAX request parameters :
searchBuilder[criteria][0][values] : [
0: "",
1: "2012-12-02"
]
searchBuilder[criteria][0][value1]: ""
searchBuilder[criteria][0][value2]: "2012-12-02"
Result is unexpected : empty string is at index 0 and 1st date is at index 1.
Expected : 1st date at index 0 and empty string at index 1.
-> details of expected value
searchBuilder[criteria][0][values] : [
0: "2012-12-02",
1: ""
]
searchBuilder[criteria][0][value1]: "2012-12-02"
searchBuilder[criteria][0][value2]: ""
Case 2) only 2nd date : OK
Same steps, but input 2012-12-02 in the 2nd field and let the 1st one empty.
Result is expected (it is the same result than the unexpected previous one, but this time it is relevant) : empty string is at index 0 and 2nd date is at index 1
0: "",
1: "2012-12-02"
Case 3) 1st and 2nd date : OK
Same steps, but input 2012-12-02 in the 1st field and input another date (Same steps, but input 2012-12-02 in the 2nd field).
Result is expected : 1st date is at index 0 and 2nd date is at index 1
0: "",
1: "2012-12-02"
A use case
With the cases 1) and 2), the request parameters are exactly the same and it is not possible to know if the value2 matches the 1st or 2nd input HTML element.
It would be convenient to know what value has been inputted. In fact, the "between" behavior triggers the request with only one field, so it would be possible in custom server-side implementation to change the between by a > condition if only the 1st field is filled, and by a < condition if only the 2nd field is filled.
To go further
Either the server-side request could be not triggered if the two dates are not filled (valid) or the described implementation (< and >) could be an improvement on server-side.
Does that make sense to order the dates, first at index 0 and second at index 1, when only one is filled, if that does not affect current implementation ?
Cheers.
Answers
Erratum for the case 3) which has an expected result (it is OK has previously said) but the code I provided is not good (my bad, with copy/paste).
It must be :
Case 3) 1st and 2nd date : OK
Same steps, but input 2012-12-02 in the 1st field and input another date (eg. 2012-12-28) in the 2nd field.
Result is expected : 1st date is at index 0 and 2nd date is at index 1