Ext.grid.Panel的数据源带参数查询时候的分页问题
store.load({params:{actorid:id}}); //根据角色ID字段提交查询请求
当我们为Ext.grid.Panel和Store分别设置了分页功能和参数的时候,我们每次在页脚点击翻页按钮其实都是针对后台网址发送新的分页参数并进行一次新的数据查询,可是点击分页的时候我们第一次向后台请求的id查询参数如果没有特殊设置的情况之下并不会再次自动附加到查询请求里面。
这时候因为缺少了查询参数id,我们的请求就不能够成功获取不到查询数据了,应该如何解决?
也就是如何能够在点击翻页按钮的时候能够让请求自动附加查询id 展开
三种方式:
使用extraParams,此法慎用
Extra parameters that will be included on every request. Individual requests with params of the same name will override these params when they are in conflict.
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url: '/users.json',
extraParams:{actorid:id
},
reader: {
type: 'json',
root: 'users'
}
},
autoLoad: true
});
2.监听beforeload事件
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
root: 'users'
}
},
listeners:{beforeload:function(store,operation, eOpts){
operation.params.actorid=id;
}},
autoLoad: true
});
3.重载/自定义pagingbar工具栏
/* MODIF BY HTZ 修正分页工具栏查询问题 */
Ext.define('Ext.toolbar.Paging', {
override : 'Ext.toolbar.Paging',
moveFirst : function() {
if (this.fireEvent('beforechange', this, 1) !== false) {
var params = this.store.lastOptions.params;
if (params) {
delete params.start;
delete params.limit;
delete params.page;
}
this.store.loadPage(1, {
params : params
});
}
},
/**
* Move to the previous page, has the same effect as clicking the 'previous'
* button.
*/
movePrevious : function() {
var me = this, prev = me.store.currentPage - 1;
if (prev > 0) {
if (me.fireEvent('beforechange', me, prev) !== false) {
var params = me.store.lastOptions.params;
if (params) {
delete params.start;
delete params.limit;
delete params.page;
}
me.store.previousPage({
params : params
});
}
}
},
/**
* Move to the next page, has the same effect as clicking the 'next' button.
*/
moveNext : function() {
var me = this, total = me.getPageData().pageCount, next = me.store.currentPage
+ 1;
if (next <= total) {
if (me.fireEvent('beforechange', me, next) !== false) {
var params = me.store.lastOptions.params;
if (params) {
delete params.start;
delete params.limit;
delete params.page;
}
me.store.nextPage({
params : params
});
}
}
},
/**
* Move to the last page, has the same effect as clicking the 'last' button.
*/
moveLast : function() {
var me = this, last = me.getPageData().pageCount;
if (me.fireEvent('beforechange', me, last) !== false) {
var params = me.store.lastOptions.params;
if (params) {
delete params.start;
delete params.limit;
delete params.page;
}
me.store.loadPage(last, {
params : params
});
}
},
/**
* Refresh the current page, has the same effect as clicking the 'refresh'
* button.
*/
doRefresh : function() {
var me = this, current = me.store.currentPage;
if (me.fireEvent('beforechange', me, current) !== false) {
me.store.loadPage(current, me.store.lastOptions);
}
}
});