【发布时间】:2012-03-26 15:16:56
【问题描述】:
使用 Ext.ux.grid.FiltersFeature,我有远程过滤器,我正在尝试编写一个函数以编程方式在网格列上应用日期过滤器(而不是单击列标题中的过滤器下拉菜单)。我第一次运行该函数时,网格存储会在没有过滤器的情况下重新加载。当我第二次(以及之后的每次)运行该函数时,它工作得很好,商店重新加载了过滤器。这是我拥有的功能的要点:
// a filter object for 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 to create the filters as soon as the grid renders
// rather than waiting for the user to click on the header
grid.filters.createFilters();
}
},
bbar: [{
text: 'Do a filter',
handler: function() {
// get the filter that is attached to the grid
var gridFilter = grid.filters.getFilter(aFilter.field);
// have to do this to create a menu for this filter
gridFilter.init({dataIndex: aFilter.field, type: aFilter.type, active: true});
// if this column is a 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});
}
}
}
}
});
我还发现,如果我在运行该函数之前单击 any 网格标题菜单,则此函数第一次起作用。
我一直在尝试找出在第一次尝试失败后对网格进行了哪些更改以使过滤器工作,或者单击 any 网格标题如何使其工作。但是我添加的任何内容似乎都无法修复它,因此它将第一次运行。有人成功实现了吗?
【问题讨论】:
-
你试过在
FiltersFeature对象上调用createFilter()吗?