用Ext Grid的翻页工具翻页后, 保留设置的查询参数:
方法一, 在beforeload中设参数,
在查询的 form中,设置
this.grid.store.on('beforeload', this.beforeDataLoad, this);
/** 加载数据前, 读取查询参数. */
beforeDataLoad : function() {
var values =this.getForm().getValues();
Ext.apply(this.grid.store.lastOptions.params, {
queryMap : values
});
},
query:function(){
this.grid.store.reload();
}
优点: 如果表单被修改, 在执行查询按钮以外的地方再载入数据时不用考虑读取查询, 可直接reload().
缺点: 可能在一些不希望查询的时候, 也会去读取查询表单的值.
方法二, 执行查询设参数
query:function(){
varvalues = this.getForm().getValues();
var params = this.grid.store.baseParams;
Ext.apply(params,values);
this.grid.store.baseParams = params;
this.grid.load();
}
这个是在网上找的, 但是用了一下后发现, 由于使用了调整当前页数据量的插件, 先翻页后查询时, 不保留翻页等信息
修改版: 适合当使用了调整当前页数据量插件时使用.
/** 查询 */
searchAction : function() {
var values = this.getForm().getValues();
Ext.apply(this.grid.store.baseParams, this.grid.store.lastOptions.params);
Ext.apply(this.grid.store.baseParams, {
queryMap : values
});
this.grid.store.load(); }
有个可能引起的问题是 : 每次查询后不是显示的第一页. 当然如果你不希望如此, 只需要修改一下start.
this.grid.store.load({params:{
start : 0
}});