我正在使用ext js 3.4并且为了过滤目的我正在使用FilterRow.js。
我想在刷新页面时存储前一个过滤器的值。 我想要这样的东西: -
plugins:[new Ext.ux.grid.FilterRow({ statefulfilter: true})];
答案 0 :(得分:1)
您可以使网格本身具有状态,并覆盖其getState
和applyState
方法以自行管理过滤器的状态。
如果that是你正在使用的插件,那就会有类似的东西(未经测试的代码):
var grid = new Ext.grid.GridPanel({
// ...
// make the grid stateful
stateful: true
,stateId: 'my-stateful-filter-grid'
// save state on filter change
,initStateEvents : function(){
Ext.grid.GridPanel.prototype.initStateEvents.call(this);
this.mon(this.getRowFilterPlugin(), 'change', this.saveState, this, {delay: 100});
}
// you may want to provide a better implementation for that (the filter
// function is not available in older browsers, notably)
,getRowFilterPlugin: function() {
return grid.plugins.filter(function(plugin) {
return plugin instanceof Ext.ux.grid.FilterRow;
})[0];
}
,getState: function() {
var state = Ext.grid.GridPanel.prototype.apply(this, arguments),
plugin = this.getRowFilterPlugin();
state.filterRow = plugin.getFilterData();
return state;
}
,applyState: function(state) {
Ext.grid.GridPanel.prototype.applyState.call(this, state);
var filterRowData = state && state.filterRow,
plugin = this.getRowFilterPlugin();
if (filterRowData) {
// temporarily replacing the method to prevent firing
// the change events multiple times
var onFieldChange = plugin.onFieldChange;
plugin.onFieldChange = Ext.emptyFn;
// restore state
plugin.eachFilterColumn(function(col) {
var name = (typeof col.id === "number") ? col.dataIndex : col.id;
col.filter.getField().setValue(data[name]);
});
plugin.onFieldChange = onFieldChange; // restore method
plugin.onFieldChange(); // resume event
}
}
});