extjs - Apply grid filter programmatically from function -
using ext.ux.grid.filtersfeature, have remote filters , trying write function apply date filter on grid column programmatically (rather clicking on filter drop down menu in column header). first time run function grid store gets reloaded without filter. when run function second time (and every time thereafter) works totally fine, store reloads filters. here gist of function have:
// filter object testing afilter = {type: 'date', field: 'a_date_field', comparison: 'gt', value: '2012-03-08 00:00:00'} var grid = ext.create('ext.grid.panel', { store: store, features: [{ ftype: 'filters', }], columns[{ header: 'id', dataindex: 'id', itemid: 'id', width: 40, }, { xtype: 'datecolumn', header: 'date', dataindex: 'a_date_field', itemid: 'a_date_field', width: 75, format:'j-m-y', filterable: true }], listeners: { 'afterrender': function() { // need create filters grid renders // rather waiting user click on header grid.filters.createfilters(); } }, bbar: [{ text: 'do filter', handler: function() { // filter attached grid var gridfilter = grid.filters.getfilter(afilter.field); // have create menu filter gridfilter.init({dataindex: afilter.field, type: afilter.type, active: true}); // if column date filter column if (gridfilter.type == 'date') { var datevalue = ext.date.parse(afilter.value, 'y-m-d h:i:s'); if (filter.comparison == 'gt') { gridfilter.setvalue({after: datevalue}); } else { gridfilter.setvalue({before: datevalue}); } } } } });
i found function works first time if click on any grid header menu before run function.
i've been trying find out changes made grid make filter work after first attempt fails or clicking on any grid header make work. nothing add seems fix run first time. has implemented successfully?
i have workaround:
bbar: [{ text: 'do filter', handler: function() { var grid = this.up('grid'); var datevalue = ext.date.parse(afilter.value, 'y-m-d h:i:s'); var value = afilter.comparison == 'gt' ? {after: datevalue} : {before: datevalue}; var gridfilter = grid.filters.getfilter(afilter.field); if (!gridfilter) { gridfilter = grid.filters.addfilter({ active: true, type: afilter.type, dataindex: afilter.dataindex, }); gridfilter.menu.show(); gridfilter.setvalue(value); gridfilter.menu.hide(); } else { gridfilter.setactive(true); } ext.function.defer(function(){ gridfilter = grid.filters.getfilter(afilter.field); gridfilter.setvalue(value); }, 10); } }]
as can see apply filter 2 times.
Comments
Post a Comment