EXT过滤有 远程过滤(remote filter)和本地过滤(local filter),本文记录的是本地过滤。
由于楼主使用的是EXTJS 5.1.0版本的MVVM模式,所以接下来的 model 和 store 都是定义成了类。
model
Ext.define('cmclouds.model.RatioStore',{
extend: 'Ext.data.Model',
fields:[
{name:'staff_name',type:'string'},
{name:'idno',type:'string'},
{name:'rdstafftype',type:'string'},
{name:'rdrole',type:'string'}
]
});
store
Ext.define('cmclouds.store.RatioStore', {
extend: 'Ext.data.Store',
alias:'store.ratio',
model:'cmclouds.model.RatioStore',
pageSize:3000,
proxy: {
type: 'ajax',
url: getRootPath()+'/business/queryRDprojStaff',
reader: {
type: 'json',
rootProperty: 'data',
totalProperty:'itemsCount',
successProperty:'success'
}
},
remoteFilter: false,//如果写成true,则会报错
});
textfield
{
width: 200,
fieldLabel: '姓名',
labelWidth: 40,
xtype: 'textfield',
listeners:{
change:function(textfield){
//定义一个正则匹配规则
var regExp = new RegExp(".*" + textfield.value+ ".*");
store.clearFilter();//清除上次的过滤条件
store.filterBy(function(record){
var staff_name = record.get('staff_name');
return regExp.test(staff_name);
})
}
}
}