Ext.grid.Panel的数据源带参数查询时候的分页问题

2025-04-26 04:52:31
推荐回答(1个)
回答1:

三种方式:

  1. 使用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);

}

}

});