Francesco Belladonna
Francesco Belladonna

Reputation: 11689

Add a "permanent" filter to a store, until I manually call clearFilter

I'm using a store to fetch the specializations of all hikers (so hiker has many specializations). However, I have a detail window where this specializations are added/removed/shown ony for currently selected hiker (yea, it's a detail window).

My problem here is that my store fetch data for all hikers, but I want it to show, when detailed window is up, only data for given hiker. Notice also that I'm showing data in data-grid, so the user possibly can add filters and I noticed that if I add a filter with store.filter({...}) and user add a filter with data-grid, my filters are removed (so basically they are useless.

Which approach should I use? Do you have any suggestion? I were thinking about 1 store for each hiker, but I don't like this solution.

Edit 1: I also noticed that I can't create a filter in the same way as data-grid builds them:

Ext.create('Ext.util.Filter', {
      type: 'numeric',
      comparison: 'eq',
      field: 'hiker_id',
      property: 'hiker_id',
      value: me.hiker.get('id'),
      root: 'data'
    })

Which is boring, because I imnplemented on server side a functionality that parses the grid filters already.

Upvotes: 0

Views: 1810

Answers (2)

Alex
Alex

Reputation: 5724

-How- are your users doing the filter?

store.filter accepts both arrays and functions, so you can do quite a bit with it, without actually juggling the data on the server. (eg manage an array that is being passed to the filter, test against an object somewhere, or whatever)

Permanent filter? Not so much, but since you can add multiple filters etc, it is relatively trivial to keep track of what filters are in place.

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-filter

Upvotes: 1

Johan Haest
Johan Haest

Reputation: 4421

We just give our filters in json format to the store's extra params. And parse that back-end. The extra params stay the same while paging or refreshing the grid.

grid.getStore().getProxy().extraParams = { filter: yourFilter };

Upvotes: 2

Related Questions