如何添加分页extjs 4网格

How to add paging to extjs 4 grid?

本文关键字:分页 extjs 网格 添加 何添加      更新时间:2023-09-26

我有一个像这样的存储,我用于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加载所有数据,并在客户端分页这些结果,而不发送服务器请求。

是可能的吗?如何做到这一点?

加载所有数据

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配置来模拟分页功能。更多信息请查看我的回答。看看这个演示吧。

更新

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

也不能在ExtJS 4.2中使用

directFn解决方案对我来说总是像一个hack。从4.0.7开始,不需要使用directFn。而是使用Ext.ux.data.PagingMemoryProxy。演示在这里