【问题标题】:Ext js paging with local data does not work带有本地数据的 Ext js 分页不起作用
【发布时间】:2015-06-15 12:53:08
【问题描述】:

我尝试使用 ExtJs4 网格启用分页。分页工具栏看起来可以工作,但网格中没有启用分页。你能帮我看看我缺少什么吗?

Ext.onReady(function () {
        var i = 1;

    Ext.define('User', {
        extend: 'Ext.data.Model',
        fields: [
             { name: 'id', type: 'int' },
             { name: 'firstName', type: 'string' },
             { name: 'lastName', type: 'string' },
             { name: 'age', type: 'int' },
             { name: 'eyeColor', type: 'string' }
        ]
    });

看起来问题出在 totalCount 上,但还有更多问题。

  var store=  Ext.create('Ext.data.Store', {
      model: 'User',
      totalCount:50,
      pageSize: 10,
      autoLoad: { start: 0, limit: 10 },

      proxy: {
          type: 'memory',
          reader: {
              root: 'users',
              totalProperty: 'totalCount'
          }

      },

  data: [
         { id: i++, firstName: 'Ed',    lastName: 'Spencer', age:20,  eyeColor: 'blue' },
         { id: i++, firstName: 'Tommy', lastName: 'Maintz',  age: 30, eyeColor: 'black' },
         { id: i++, firstName: 'Aaron', lastName: 'Conran',  age: 40, eyeColor: 'blue' },
         { id: i++, firstName: 'Jamie', lastName: 'Avins',   age: 50, eyeColor: 'black' },
         { id: i++, firstName: 'Ed',    lastName: 'Spencer', age: 20, eyeColor: 'blue' }

                                                 .
                                                 .
                                                 .

        ]
    });

分页工具栏看起来可以正常工作,但网格值不会根据页码而改变。

     Ext.create('Ext.grid.Panel', {
        title: 'Users',
        store: store,
        proxy: {
            type: 'memory',
            enablePaging: true
        },
        columns: [
              { header: 'ID', dataIndex: 'id', width:50 },
            { header: 'Name', dataIndex: 'firstName' },
            { header: 'Last Name', dataIndex: 'lastName' },
            { header: 'Age', dataIndex: 'age', width: 50 },
            { header: 'Eye Color', dataIndex: 'eyeColor' }

        ],
        height: 600,
        width: 800,
        dockedItems: [{
            xtype: 'pagingtoolbar',
            store: store,
            pageSize: 10,
            dock: 'bottom',
            displayInfo: true
        }],
        renderTo: Ext.getBody()
    });


});

【问题讨论】:

    标签: javascript extjs extjs4.2 pagingtoolbar


    【解决方案1】:

    您需要proxy: 'pagingmemory',即Ext.ux.data.PagingMemoryProxy

    来自doc

    使用本地数据进行分页

    也可以通过扩展使用本地数据来完成分页:

    • Ext.ux.data.PagingStore
    • 分页内存代理 (examples/ux/PagingMemoryProxy.js)

    还要注意,不需要有:

    • totalCount 在商店配置中(它将由代理提供);
    • proxy 在网格上(它已经在商店内);
    • pageSize 在分页工具栏配置中(将从商店中获取)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-24
      • 2018-05-18
      相关资源
      最近更新 更多