【问题标题】:Extjs buffered store loads all new added itemsExtjs 缓冲存储加载所有新添加的项目
【发布时间】:2015-12-22 13:31:01
【问题描述】:

我正在尝试将 Ext 的 (4.1.1) 缓冲存储/网格组合与数据一起使用,我无法通过 rest Api 直接访问这些数据.. 左右,但传入的数据由我的控制器,只想将此数据添加到缓冲网格中。

问题来了,当我将 500 个项目直接加载到商店时,缓冲正在工作.. 只有我能看到的项目才会被渲染,但是当我开始 store.add(items) 时,它们都会自动渲染..

这是我的商店和网格:

商店

this.store = Ext.create('Ext.data.ArrayStore', {
    storeId: 'reportDataStore',
    fields: [
        { name: 'html'}
    ],
    buffered: true,
    pageSize: 100,
    autoLoad: true
});

网格

  {
      xtype: 'gridpanel',
      flex: 1,
      hideHeaders: true,
      store: this.store,
      verticalScroller: {
          rowHeight: 43
      },
      disableSelection: true,
      columns: [
          { header: '', dataIndex: 'html', flex: 1 }
      ]
  }

数据控制器

...
// somewhere in initialization process of the controller, 
// I take the reportDataStore, for later reusing
    this.reportDataStore = Ext.getStore('reportDataStore');
...
onNewData: function(data) {
    this.reportDataStore.add(data)
}

所以我的期望是,数据会进入存储,但只有可见数据会被渲染。现在是这样,所有新数据都会被渲染。

【问题讨论】:

    标签: extjs grid store extjs4.1 buffered


    【解决方案1】:

    我无法使用您提供的代码生成一个工作示例,但我有一些接近的东西...您是如何设法将记录添加到由内存代理支持的缓冲存储的?

    您应该尝试将新数据直接推送到代理,然后重新加载存储,如下所示:

    store.proxy.data.push(data);
    
    grid.view.saveScrollState();
    
    // should probably have been a call to reload(), but then the loading never ends...
    store.load({
        callback: function() {
            grid.view.restoreScrollState();
        }
    });
    

    请参阅this fiddle,它会尝试重现您的设置。

    【讨论】:

    • 非常感谢,这似乎是我正在寻找的东西,但我对 pageSize 发生了一些误解(当 pageSize 是可能项目的最大值时,它效果最好)和排序不起作用,需要我自己在 store.proxy.data 数组上实现它。或者你能不能展示如何在 id (DESC) 上排序
    • 缓冲存储使用 pageMap 将大小为 pageSize 的页面保存在内存中(请参阅constructor 代码中的相关部分)。不幸的是,内存代理是一个非常轻量级的实现,不支持分页(参见code)。这就是为什么我们需要在 store 中有一个巨大的 pageSize(大于记录的总数,否则会损坏)。
    • 正如您所指出的,它也不支持排序。我忘记了它存在于 Ext 4.1 中,但您应该尝试使用 PagingMemoryProxy 代替,它支持分页和排序(再次,您应该查看代码)。
    • 谢谢 rixo,我做到了。它看起来很有希望;)感谢您对 PagingMemoryProxy 提出的意见,将看看它
    猜你喜欢
    • 1970-01-01
    • 2014-02-05
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    相关资源
    最近更新 更多