使用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});
}
}
}
}
});
我還發現,此功能在第一時間,如果我任何網格標題菜單上單擊之前,我運行的功能。
我一直在試圖找出在第一次嘗試失敗後或者點擊任意網格標頭確實能夠工作的情況下,使濾鏡工作的網格發生了哪些更改。但我沒有添加任何東西似乎可以解決它,所以它會第一次運行。有沒有人成功實現了這個?
您是否嘗試過在'FiltersFeature'對象上調用'createFilter()'? – 2012-03-26 23:03:22