在ajax类型的Extjs 5存储上进行本地分页 [英] Locally paging on Extjs 5 store of type ajax

查看:119
本文介绍了在ajax类型的Extjs 5存储上进行本地分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,从一开始就加载所有数据并不是很麻烦.

I am working on an app where loading all data from the beginning is not really an inconvenient.

我正在通过Ajax从服务器获取json数据,而我的存储非常简单:

I am getting json data from a server through Ajax, and my store for doing that is pretty simple:

Ext.define('MODIFE.store.CentroBeneficio', {
    extend  : 'Ext.data.Store',
    requires : [
        'MODIFE.model.CentroBeneficio'
    ],
    storeId : 'CentroBeneficio',
    model   : 'MODIFE.model.CentroBeneficio',
    page-size: 10,
    proxy   :{
        //type: 'memory',
        type: 'ajax',
        enablePaging: true,
        url: 'http://'+MODIFE.Global.ip+'/CentroBeneficio/GetCentroBeneficios'
    },
    autoLoad: true
});

这是我的模特

Ext.define('MODIFE.model.CentroBeneficio', {
    extend: 'Ext.data.Model',
    storeId: 'CentroBeneficio',
    pageSize: 10,
    fields: [
        {name:'IdCentroBeneficio', type:'int'},
        {name:'CompaniaCodigo', type:'int'},
        {name:'codigo', type:'string'},
        {name:'description', type:'string'},
        {name:'complete_description', type:'string', convert : function(v, record) {return record.data.codigo+' - '+record.data.description;}},
        {name:'status', type:'int', convert : function(v, record) {return (record.data.status == 1) ? 'Activo' : 'Inactivo';}},
        {name:'name_compania', type:'string'},
        {name:'pais', type:'string'},
        {name:'IdPais', type:'int'}

    ]
});

我想实现的是对已加载的数据进行分页.我尝试将类型"memory"指定为"pagingmemory",但不会加载任何内容,这会导致浏览器死(我不知道为什么).

What I would like to achieve is paging the already loaded data. I tried specifying the type to 'memory' which didn't load anything as well as 'pagingmemory', wich caused the browser to die (I don't know why).

我已经在视图上设置了分页栏:

I have already the paging bar set up on my view:

    {
            xtype: 'grid',
            id: 'centroBeneficioGrid',
            title: getLabelByKey('CentroBeneficio_SearchGridTitle_Listado'),
            store: 'CentroBeneficio',
            columns: [
                { text: getLabelByKey('CentroBeneficio_SearchColumnGrid_Pais'),  dataIndex: 'pais', flex: 2},
                { text: getLabelByKey('CentroBeneficio_SearchColumnGrid_Company'), dataIndex: 'name_compania', flex: 3},
                { text: getLabelByKey('CentroBeneficio_SearchColumnGrid_CentroBeneficio'), dataIndex: 'codigo', flex: 2},
                { text: getLabelByKey('CentroBeneficio_SearchColumnGrid_Descripcion'), dataIndex: 'description', flex: 4},
                { text: getLabelByKey('CentroBeneficio_SearchColumnGrid_Estatus'), dataIndex: 'status', flex: 2}
            ],
            listeners: {
                itemdblclick: 'CBSelectedGrid'
            },
            dockedItems: [{
                xtype: 'pagingtoolbar',
                store: 'CentroBeneficio',
                dock: 'bottom',
                displayInfo: true
            }],
        } 

它可以正确显示,但只将所有数据加载到第一页上.预先感谢.

It shows up correctly but it just loads all data on the first page. Thanks in advance.

推荐答案

使用

Paging of already loaded data is achieved with Ext.data.proxy.Memory configured with enablePaging: true. So what you need is to use two stores:

  1. 远程"存储区仅用于从服务器端加载数据;
  2. 使用内存代理配置的本地分页存储.数据一旦加载完毕,就会从远程存储中加载:

pagingStore.getProxy().setData(remoteStore.getRange());
pagingStore.load();

完整的示例: https://fiddle.sencha.com/#fiddle/pim

这篇关于在ajax类型的Extjs 5存储上进行本地分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆