extjs表格搜索框代码
时间: 2023-03-29 07:01:37 浏览: 161
使用FlexiGrid实现Extjs表格的效果.doc
以下是一个简单的 extjs 表格搜索框代码示例:
```
Ext.create('Ext.toolbar.Toolbar', {
renderTo: Ext.getBody(),
items: [{
xtype: 'textfield',
fieldLabel: '搜索',
labelWidth: 50,
width: 200,
enableKeyEvents: true,
listeners: {
keyup: function(field, e) {
var value = field.getValue();
var store = Ext.getCmp('myGrid').getStore();
store.clearFilter();
if (value) {
var regex = new RegExp(value, "i");
store.filterBy(function(record) {
return regex.test(record.get('name'));
});
}
}
}
}]
});
Ext.create('Ext.grid.Panel', {
id: 'myGrid',
renderTo: Ext.getBody(),
store: Ext.create('Ext.data.Store', {
fields: ['name', 'email', 'phone'],
data: [{
name: 'Lisa',
email: 'lisa@simpsons.com',
phone: '555-111-1224'
}, {
name: 'Bart',
email: 'bart@simpsons.com',
phone: '555-222-1234'
}, {
name: 'Homer',
email: 'homer@simpsons.com',
phone: '555-222-1244'
}, {
name: 'Marge',
email: 'marge@simpsons.com',
phone: '555-222-1254'
}]
}),
columns: [{
text: '姓名',
dataIndex: 'name'
}, {
text: '邮箱',
dataIndex: 'email'
}, {
text: '电话',
dataIndex: 'phone'
}]
});
```
阅读全文