1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    0
    dadofgage is on a distinguished road

      0  

    Default store.filter with a date range

    store.filter with a date range


    I have tried a couple of different methods to filter my store using a date range, I feel as though I am close but just off a bit - can you point me in the right direction?

    Code:
    if ('fromdate' in $_GET) {
                            store.filter([
                                    {property: 'CollectTime' , value: record.get('CollectTime') >= $_GET['fromdate'] && record.get('CollectTime') <= $_GET['todate'] , anyMatch: true , caseSensitive: false}
                                    
                             ]);
                    }

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,154
    Vote Rating
    475
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    store.filter() is for use in the store load listener.
    If you want to apply a filter after, please use filterBy()

    Scott.

  3. #3
    Sencha User
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    0
    dadofgage is on a distinguished road

      0  

    Default


    so is this then incorrect even though it works?

    Code:
    var events_ds = new Ext.data.JsonStore({
                    autoLoad: true,
                    autoDestroy: true,
                    url: '<% $base %>json/events/<% $eventWWN %>.json',
                    storeId: 'events_ds',
                    idProperty: 'id',
                    fields: [ 'id', 'precedence', 'affectedWWN', 'eventType', 'color', 'CollectTime' ]
    
    listeners: {
            'load': function(store) {
                    if ('priority' in $_GET) {
                            store.filter([
                                    {property: 'precedence' , value: $_GET['priority'] , anyMatch: true , caseSensitive: false}
                            ]);
                    }
                    if ('color' in $_GET) {
                            store.filter([
                                    {property: 'color' , value: $_GET['color'] , anyMatch: true , caseSensitive: false}
                            ]);
                    }
    
            }
    }
    I figured that if I showed my code a bit more it might help.

    Just wanting to make sure I am doing this correctly.

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,154
    Vote Rating
    475
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Based on your original code, I was not sure you were using a button or store load.

    Can you describe your problem in more detail. Is the filter not working at all, or just the wrong data?

    Are you sure your values are resolving in time using $_GET() in your JS code?

    Scott.

  5. #5
    Sencha User
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    0
    dadofgage is on a distinguished road

      0  

    Default


    Quote Originally Posted by scottmartin View Post
    Can you describe your problem in more detail. Is the filter not working at all, or just the wrong data?
    What I am trying to do is to add a third filter that will filter on a field called 'CollectTime'.

    I have the form (that was created using ExtJS) and it is passing the variables 'fromdate' and 'todate' correctly (via $_GET).

    Now, I am trying to add in the final filter that will allow the selected date range to be the only data that is shown, I'm just not sure of the syntax to make it work where I am trying to do a date range

    Code:
     
     if ('fromdate' in $_GET) {                         store.filter([                                  {property: 'CollectTime' , value:  record.get('CollectTime') >= $_GET['fromdate'] &&  record.get('CollectTime') <= $_GET['todate'] , anyMatch: true ,  caseSensitive: false}                                                            ]);                 }

  6. #6
    Sencha User
    Join Date
    May 2012
    Posts
    29
    Vote Rating
    0
    dadofgage is on a distinguished road

      0  

    Default


    Here is my entire set of code as it currently stands where I am grabbing the data and then filtering it:

    Code:
    var events_ds = new Ext.data.JsonStore({
                    autoLoad: true,
                    autoDestroy: true,
                    url: '<% $base %>json/events/<% $eventWWN %>.json',
                    storeId: 'events_ds',
                    idProperty: 'id',
                    fields: [ 'id', 'precedence', 'affectedWWN', 'eventType', 'color', 'CollectTime' ],
    
    listeners: {
            'load': function(store) {
                    if ('priority' in $_GET) {
                            store.filter([
                                    {property: 'precedence' , value: $_GET['priority'] , anyMatch: true , caseSensitive: false}
                            ]);
                    }
                    if ('color' in $_GET) {
                            store.filter([
                                    {property: 'color' , value: $_GET['color'] , anyMatch: true , caseSensitive: false}
                            ]);
                    }
    
    if ('fromdate' in $_GET) {
            store.filter([
    
    {
            fn: function(record) {
            return (record.get('CollectTime') >= $_GET['fromdate'])
            },
            scope: this
    }
    
    
            ]);
    }

Thread Participants: 1

Tags for this Thread