As an update, I expanded this feature and modified it to work with ExtJS 4.1.1
Here is an example of a function that allows you to dynamically set grid filters (without having to click on the menu items). After that, the filtered elements will be visible to the user in the menu of the column headers of the grid, as if he clicked on them and set them manually.
The grid argument is the FiltersFeature
grid that you want to filter. Another argument is an array of filter objects (I will show an example below), the function simply applies all the transferred filtering objects to the grid.
doGridFilter: function(grid, filters) { // for each filter object in the array Ext.each(filters, function(filter) { var gridFilter = grid.filters.getFilter(filter.field); gridFilter.setActive(true); switch(filter.data.type) { case 'date': var dateValue = Ext.Date.parse(filter.data.value, 'm/d/Y'), value; switch (filter.data.comparison) { case 'gt' : value = {after: dateValue}; break; case 'lt' : value = {before: dateValue}; break; case 'eq' : value = {on: dateValue}; break; } gridFilter = log.filters.getFilter(filter.field); gridFilter.setValue(value); gridFilter.setActive(true); break; case 'numeric': var value; switch (filter.data.comparison) { case 'gt' : value = {gt: filter.data.value}; break; case 'lt' : value = {lt: filter.data.value}; break; case 'eq' : value = {eq: filter.data.value}; break; } gridFilter = log.filters.getFilter(filter.field); gridFilter.setValue(value); gridFilter.setActive(true); break; case 'list': gridFilter = log.filters.getFilter(filter.field); gridFilter.menu.setSelected(gridFilter.menu.selected, false); gridFilter.menu.setSelected(filter.data.value.split(','), true); break; default : gridFilter = log.filters.getFilter(filter.field); gridFilter.setValue(filter.data.value); break; } }); }
Here is an example of an array of filter objects.
// an example of a "filters" argument [{ field: 'some_list_column_data_index', data: { type: 'list', value: 'item1,item2,item3,item4,item5,item6,item7' } }, { field: 'some_date_column_data_index', data: { type: 'date', comparison: 'gt', value: '07/07/2007' } }]
Caution, you need to "create" filters manually before using this function. Typically, FiltersFeature
mesh filters are “created” the first time the user FiltersFeature
one of them, which might not happen if the user just wants to apply one of these predefined filters.
This can be easily handled by turning on this listener after listening to the grid.
listeners: {