Extjs3.4从网格存储中获取超过1页的所有数据

时间:2013-11-07 07:01:51

标签: extjs extjs3

如何从网格中获取超过1页的所有数据?

我只设置在一个页面中显示50条记录,但我的总数据最多为52条记录,存储为2页。


enter image description here

我可以知道如何从这两页获取所有数据吗?

以下是只能获得1页数据的代码......

ExportButtonTestJS = Ext.extend(One.Report, {
    reportName: 'ExportButtonTestRpt',
    autoExecute: true,
    isDetailPage: false,
    listeners: {
        bbarconfig: function(report, bbarConfig) {
          bbarConfig.items.push({
            xtype: 'button',
            text: 'Export',
            disabled: false,
            onClick : function () {
                console.log(report.grid.getStore().data.items);
                }
          });
        }
    }
});

3 个答案:

答案 0 :(得分:6)

Ext.data.store的默认页面大小为50。因此,即使存储中的数据超过50条记录(例如400条记录),任何时候只有50条记录将存储在Ext.store中。一旦我们转到下一页,下一个记录将从51到100条记录存储在商店中。

满足您要求的两种解决方案:

  1. 根据需要增加pageSize - 例如:pageSize:500
  2. 在Ext.data.store
  3. 中设置buffered:true

    在设置buffered:true时,您可以使用grid.store.getRange(start, end)一次获取商店的所有记录。但在这种情况下,您需要第一次加载商店。

答案 1 :(得分:2)

遇到同样的问题,这是我为了从所有页面获取数据而必须做的事情:

var grid = Ext.getCmp('myGrid');    

//store current pageSize
var currentPageSize = grid.getBottomToolbar().pageSize;

var store = grid.getStore();     // store from grid 

//reload store with total nº of records     
store.reload({params:{start:0,limit:store.getTotalCount()}});

//once the grid is reloaded with all records, then do whatever you need.
store.on('load', function(store, recs, opt){

      var selected = store.getRange();  // getRange = get all records

      //this iterates over all records
      Ext.each(selected, function(item) {
           process here;
      }, this);

      //once you finished processing, reload grid with previous pageSize
      store.reload({params:{start:0,limit:currentPageSize}});
}, this, {single: true}); //single:true says this event will only trigger once

希望这对任何人都有所帮助,花了我一些时间让这个工作。

答案 2 :(得分:1)

请勿尝试直接访问项目。使用商店方法。

尝试report.grid.getStore().getRange()

请参阅http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-getRange

相关问题