extjsextjs7

Extjs 7.2.0 - Remote Filtering problem with multiple filters on same field


I have an Ext grid and store. The store fields are

fields: ['id', {
  name: 'name',
  type: 'string'
}, {
  name: 'dob',
  type: 'date'
}]

The relevant grid column for date is set as

{
  xtype: 'datecolumn',
  dataIndex: 'dob',
  text: 'Date of Birth',
  format: 'd-m-Y',
  filter: 'date'
}

Here, the filter attribute is for the gridfilters plugin.

I would also like to have the filters applied programmatically on the dob field like so -

store.filter([{
  property: 'dob',
  value: new '01/17/1990',
  operators: 'gt'
},{
  property: 'dob',
  value: '01/17/2022',
  operators: 'lt'
}])

However, although the gridfilter plugin works with multiple filters on the same field, programmatically this doesn't. It only applies the last filter from the array.

With the gridfilter plugin, I get multiple filters like -

[
  {
    "property": "dob",
    "operator": "lt",
    "value": "18/01/1990"
  },
  {
    "property": "dob",
    "operator": "gt",
    "value": "18/01/2022"
  }
]

However, when I try it programmatically, I only get -

[
  {
    "property": "dob",
    "operator": "gt",
    "value": "18/01/2022"
  }
]

Any suggestions toward this will be very helpful.

I've created a Sencha Fiddle to demonstrate the issue. Sencha Fiddle


Solution

  • You can add multiple filters for the same property by setting a different id property for the filters. Change this in your code:

    if (from && to){
        var filters = [{
            id: 1,
            property: 'dob',
            operator: 'gt',
            value: from
        },{
            id: 2,
            property: 'dob',
            operator: 'lt',
            value: to
        }]
    
        store.filter(filters);
    }
    

    If you change it in your fiddle, under Filters Applied you will see that both filters are set this way. Anyway, I think you need to adjust this a bit to actually work, because your dates are stored currently as text.