react AG-grid: date filter in range - doesn't work if you reverse the dates

Viewed 1049

I'm trying to set up a date filter on ag-grid as per this link. The main difference is that ag-grid prefers date format dd/mm/yyyy whereas my dates are in yyyy-mm-dd.

comparator:function (filterLocalDateAtMidnight, cellValue){
    let dateParts  = cellValue.split("-");
    let cellDate = new Date(Number(dateParts[0]), Number(dateParts[1]) - 1, Number(dateParts[2]));
    if (cellDate < filterLocalDateAtMidnight) {
        return -1;
    } else if (cellDate > filterLocalDateAtMidnight) {
        return 1;
    } else {
        return 0;
    }

The above code works conventionally, although I noticed a special case. when selecting the date filter condition "inRange", and setting the dates e.g:

dateFrom = 2017-07-13
dateTo = 2017-08-20

it works fine and i see records between those two dates, but if you reverse the dates, i.e.:

dateFrom = 2017-08-20
dateTo = 2017-07-13

No records show. How can I overcome this glitch? Conventionally, the user would put the earliest date first, but that doesn't mean the above scenario isn't possible

0 Answers
Related