【问题标题】:pagination not working correctly in extjs分页在 extjs 中无法正常工作
【发布时间】:2015-04-20 18:46:50
【问题描述】:

在 JSON 中,我的总数为 67,但在网格上仅显示两条记录。分页工具栏显示 msg "Displaying 1 - 2 of 2" 并且下一个和上一个按钮也被禁用 下面是我的 js 文件的代码。 如何验证 totalProperty 的总数是否正确?

Ext.onReady(function(){

var simpsonsStore = Ext.create('Ext.data.Store', {
    storeId: 'simpsonsStore',
    pageSize: 2,
    autoLoad: false,
    buffered: true,
    fields: ['name', 'email', 'phone'],
    proxy: {
        type: 'ajax',
        pageParam: undefined,
        url: '/apex/getPatientData',
        startParam: 'start',
        limitParam: 'limit',
        noCache: false,
        reader: {
            type: 'json',
            root: 'items',
            totalProperty: 'total'
        }
    },

});
simpsonsStore.load({
    params: {
        start: 0,
        limit: 2
    }
});
Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [{
        header: 'Name',
        dataIndex: 'name'
    }, {
        header: 'Email',
        dataIndex: 'email',
        flex: 1
    }, {
        header: 'Phone',
        dataIndex: 'phone'
    }],
    height: 200,
    width: 400,
    dockedItems: [{
        xtype: 'pagingtoolbar',
        store: simpsonsStore, 
        dock: 'bottom',
        displayInfo: true
    }],
    renderTo: Ext.getBody()
});

});

【问题讨论】:

    标签: ajax json extjs proxy store


    【解决方案1】:

    只有在您将限制参数设置为 2 时才会显示两条记录:

    params: {
                start: 0,
                limit: 2
            }
    

    您在商店中的 pageSize 也设置为 2,因此当它加载数据时,它会将您商店中的一页数据视为最多 2 条记录。请参阅文档 - http://docs.sencha.com/extjs/4.2.0/#!/api/Ext.data.Store-cfg-pageSize

    【讨论】:

    • 即使我增加限制(比如 10),网格也会加载 10 条记录,并且分页工具栏上的消息显示“显示 1-10 个,共 10 个”,但总数为 67,这是 JSON 响应:0 : {rnum: 1, begin: "0", end: "10", total: 67, name: "1A", email: "Guruprit",…}。我认为总属性没有正确映射,但我不知道如何验证在阅读器中是否正确设置了总属性。
    【解决方案2】:

    您的 JSON 很可能没有记录 totalProperty: 'total'这个字段需要返回所有记录的个数

    { 'total': 67, 'items': [{ .... }] }

    【讨论】:

      【解决方案3】:

      好的,您的问题看起来是您的 json 响应的结构。

      @nniicc 走在正确的轨道上,您的 JSON 证明了这一点,因为您返回数据行中的总数,而不是作为 JSON 对象的单独属性

      {rnum:1,开始:“0”,结束:“10”,总数:67,名称:“1A”,电子邮件: “古鲁普里特”,……}

      所以应该更像这样

      {
          'total': 67,
          'items': [{rnum: 1, begin: "0", end: "10", name: "1A", email: "Guruprit",…},
      ...]
      }
      

      【讨论】:

        猜你喜欢
        • 2012-06-30
        • 2013-11-03
        • 1970-01-01
        • 1970-01-01
        • 2023-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多