使用本地数据的Ext js分页不起作用

时间:2015-06-15 12:53:08

标签: javascript extjs extjs4.2 pagingtoolbar

我尝试使用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()
    });


});

1 个答案:

答案 0 :(得分:0)

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

来自doc

  

使用本地数据进行分页

     

也可以使用扩展程序使用本地数据完成分页:

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

另请注意,没有必要:

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