如何向extjs 4 grid添加分页?

时间:2011-09-11 09:06:38

标签: javascript extjs extjs4

我有一个这样的商店,我用于extjs网格

Ext.create('Ext.data.Store', {
    autoLoad : true,
    fields   : [
        {name: 'item_code', mapping: 'item_code', type: 'string'},
        {name: 'quantity', mapping: 'quantity', type: 'string'},
        {name: 'description', mapping: 'description', type: 'string'},
        {name: 'selling_price', mapping: 'selling_price', type: 'string'},
        {name: 'discount', mapping: 'discount', type: 'string'}
    ],
    storeId  : 'available_products',
    proxy    : {
        type            : 'ajax',
        actionMethods   : 'POST',
        url             : 'http://192.168.1.6/transactions/distribution_store',
        reader: {
            type: 'json',
            root: 'data'
        }
    }
});

我想在网格中添加分页,但我希望它像这样

首先使用json加载所有数据,并在客户端分页这些结果,而不发送服务器请求。

有可能吗? 怎么做?

此致

1 个答案:

答案 0 :(得分:4)

用于加载所有数据

var myData = [];
Ext.Ajax.request({
    url: 'http://192.168.1.6/transactions/distribution_store',
    method: 'POST',
    success: function(response){
        myData = Ext.decode(response.responseText);
    }
});

加载所有数据后,您可以使用directFn config来模拟分页功能。查看我的回答here了解更多信息。并查看this demo

更新

  

该解决方案不适用于ext js 4.1.1。你能为这个版本提供一个例子吗?

     

对ExtJS 4.2也不起作用。

directFn解决方案对我来说似乎总是很糟糕。从4.0.7开始,无需使用directFn。而是使用Ext.ux.data.PagingMemoryProxy。演示是here