如何像JqGrid中那样创建ExtJS网格工具栏搜索
How to create ExtJS Grid toolbar search like in JqGrid
我刚开始深入ExtJS网格,我想创建一些工具栏搜索,比如下面的JqGrid。网格将根据该列中键入的键显示结果。有人能带我参观一下吗^_^提前感谢您的回答。
jqgridhttp://fbcdn-sphotos-a.akamaihd.net/hphotos-ak-ash4/379109_10150531271858928_704228927_8868872_1607857946_n.jpg
我这样做的方法是在包含搜索字段的网格面板中添加一个顶部工具栏。然后就是将事件与回调挂钩的问题。
下面是ExtJS3.x的一个例子。它是从我的项目中编辑出来的代码,所以我可能删掉了太多,或者留下了一些不需要的东西。请特别参阅buildTBar()、buildSearchBar()和attachListeners()方法。
Ext.ns('MyNs');
MyNs.GridPanel = Ext.extend(Ext.grid.GridPanel,{
initComponent: function() {
this.colModel = this.buildColModel();
this.store = this.buildStore();
this.tbar = this.buildTBar();
MyNs.GridPanel.superclass.initComponent.call(this);
this.attachListeners();
},
attachListeners: function() {
this.on('render', function() {
this.getPagingBar().bindStore(this.getStore());
this.getSearchBar().bindStore(this.getStore());
});
//I use this grid in a tab, so I defer loading until tab is activated
this.on('activate',function() {
var store = this.getStore();
if(store.getCount() == 0) {
store.load({
params: {
start: 0,
limit: 20
}
})
}
});
},
buildColModel: function() {
return new Ext.grid.ColumnModel({
columns: [
{header: 'Index', dataIndex: 'index'}
]
})
},
buildStore: function() {
//return a store
},
buildTBar: function() {
var items = new Array(
this.buildPagingBar(),
this.buildSearchBar()
)
return {
xtype: 'panel',
items: items
}
},
buildPagingBar: function() {
return {
xtype: 'paging',
pageSize: 20,
displayInfo: true,
displayMsg: 'Records{0} - {1} z {2}',
}
},
buildSearchBar: function() {
return {
xtype: 'toolbar',
itemId: 'searchBar',
items: [
{xtype: 'textfield', itemId: 'index'},
],
bindStore: function(store) { //here we bind grid's store to searchbar
this.store = store;
var me = this;
store.on('beforeload', function(store, options) {
options.params.index = me.find('itemId','index')[0].getValue();
})
Ext.each(this.findByType('textfield'),function(field) { //let's have store reloaded on field changes
field.on('change', function(field, newValue, oldValue) {
store.reload();
})
})
}
}
},
getPagingBar: function() {
return this.getTopToolbar().findByType('paging')[0];
},
getSearchBar: function() {
return this.getTopToolbar().find('itemId','searchBar')[0];
}
});
相关文章:
- ExtJS网格单元格编辑器,防止焦点松动问题
- 如何使ExtJS网格面板成为真正的只读组件
- Extjs 4网格:根据存储文本值在单元格中放置图标
- ExtJS网格在存储更新后未刷新
- 如何在ExtJS网格上创建带有标签的文本字段
- ExtJS网格未从Ext.data.XmlStore加载数据
- 由于本地存储代理,Extjs网格面板最多显示25行.如何更改此限制值
- extJs 5 - 网格多级分组
- 在ExtJs 4网格中强制执行唯一键值
- extjs网格真实的完全后渲染事件
- EXTJS 4.2-网格面板多网格排序
- 将数据从服务器端加载到 ExtJs 网格中
- 如何使ExtJS网格响应
- Extjs 4.2.1-网格掩码获胜'不要藏起来
- 如何使用Asp.net Websvice绑定ExtJS网格
- ExtJs 4.1网格's分组功能启用和禁用问题
- 在extjs网格4.0中获取textfield单元格td
- ExtJS 5.1 - 网格与网格过滤器插件在网格重新配置后中断
- ExtJS:网格和表单之间的双向绑定
- Extjs 网格列 - 组合在值更改后显示键而不是值