Search code examples
javascriptextjsextjs3date-range

Extjs store.filter by date range


Here is my code, I am trying to filter the 'CollectTime' by allowing it to be a date range.

I don't see in the docs where I can add this nor do I see an example that shows this working correctly.

Can someone point me in the right direction?

listeners: {
    'load': function(store) {
            if ('color' in $_GET) {
                    store.filter([
                            {property: 'color' , value: $_GET['color'] , anyMatch: true , caseSensitive: false}
                    ]);
            }
            if ('priority' in $_GET) {
                    store.filter([
                            {property: 'precedence' , value: $_GET['priority'] , anyMatch: true , caseSensitive: false}
                    ]);
            }
            if ('startdate' in $_GET) {
                    store.filter([
                            {property: 'CollectTime' , value: $_GET['startdate'] , anyMatch: true , caseSensitive: false}
                    ]);
            }
    }

}


Solution

  • use filterBy method instead of filter and provide a filter function

    here is an example:

    ...
    if ( 'startdate' in $_GET ) {
        store.filterBy( function( rec, id ){
            return rec.data.CollectTime >= $_GET['startdate'] && rec.data.CollectTime <= $_GET['enddate'];
        } );
    }
    ...