2013-05-14 41 views
4

带编辑器网格的缓冲存储区。EXTJS 4.2.0.663:带编辑器网格的缓冲存储区

我们一直在使用4.1.1版本并且正在迁移到4.2.0.663。我们拥有包含大量数据的缓冲存储的编辑网格。编辑器网格类似于行编辑示例(除了它使用缓冲存储)。但对于电网的附加功能已经迁移后停止,它会引发错误

Ext.Error: insert operation not supported into buffered Store.

var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', { 
     clicksToMoveEditor: 1, 
     autoCancel: false 
    }); 
// create the grid and specify what field you want 
// to use for the editor at each column. 
var grid = Ext.create('Ext.grid.Panel', { 
    store: store, 
    columns: [{ 
     header: 'Name', 
     dataIndex: 'name', 
     flex: 1, 
     editor: { 
      // defaults to textfield if no xtype is supplied 
      allowBlank: false 
     } 
    }, { 
     header: 'Email', 
     dataIndex: 'email', 
     width: 160, 
     editor: { 
      allowBlank: false, 
      vtype: 'email' 
     } 
    }, { 
     xtype: 'datecolumn', 
     header: 'Start Date', 
     dataIndex: 'start', 
     width: 90, 
     editor: { 
      xtype: 'datefield', 
      allowBlank: false, 
      format: 'm/d/Y', 
      minValue: '01/01/2006', 
      minText: 'Cannot have a start date before the company existed!', 
      maxValue: Ext.Date.format(new Date(), 'm/d/Y') 
     } 
    }, { 
     xtype: 'numbercolumn', 
     header: 'Salary', 
     dataIndex: 'salary', 
     format: '$0,0', 
     width: 90, 
     editor: { 
      xtype: 'numberfield', 
      allowBlank: false, 
      minValue: 1, 
      maxValue: 150000 
     } 
    }, { 
     xtype: 'checkcolumn', 
     header: 'Active?', 
     dataIndex: 'active', 
     width: 60, 
     editor: { 
      xtype: 'checkbox', 
      cls: 'x-grid-checkheader-editor' 
     } 
    }], 
    renderTo: 'editor-grid', 
    width: 600, 
    height: 400, 
    title: 'Employee Salaries', 
    frame: true, 
    tbar: [{ 
     text: 'Add Employee', 
     iconCls: 'employee-add', 
     handler : function() { 
      rowEditing.cancelEdit(); 

      // Create a model instance 
      var r = Ext.create('Employee', { 
       name: 'New Guy', 
       email: '[email protected]', 
       start: Ext.Date.clearTime(new Date()), 
       salary: 50000, 
       active: true 
      }); 

      store.insert(0, r); 
      rowEditing.startEdit(0, 0); 
     } 
    }], 
    plugins: [rowEditing], 
}); 

请对什么是应遵循的方法提出建议。

+0

您是否提交过错误或升级? – dbrin 2013-07-29 17:55:04

+0

不,我没有提交错误,也无法升级,因为我们在大规模使用缓冲存储,并需要能够使用它与编辑器网格。 – 2013-07-30 04:57:26

回答

2

与行编辑插件有类似的问题。看起来这个问题与缓冲存储内部结构有关。要解决此问题,您可以:

  1. 扩展行编辑插件并更改插入数据的方式。在插入数据的重载当前页之后说...
  2. 从使用缓冲存储器切换到为网格使用bufferedrenderer插件。这个插件的快速浏览你可以在这里找到:bufferedrenderer
  3. 做一些更深入的研究,可能有一个解决方案,即使没有消除缓冲的商店。

我我的情况下,我会选择第二种方式,除非我在ExtJS的4.2缓冲存储的变化澄清一切......

UPDATE:看来,缓冲专卖店在4.2有限functionalty。他们仍然是越野车。现在有这个问题:commit bug

+0

Ext Js提供了很多错误修正,他们特别[修复了很多缓存的商店错误](http://cdn.sencha.com/ext/beta/4.2.1.744/release-notes.html) – Christoph 2013-06-17 11:37:02

2

我也有这个问题后迁移到Ext Js 4.2。我通过创建缓冲存储的临时副本而无需缓冲来解决此问题。应用于您的代码,如下所示:

tbar: [{ 
    handler : function() { 
     rowEditing.cancelEdit(); 

     // Create a model instance 
     var r = Ext.create('Employee', { 
      name: 'New Guy', 
      email: '[email protected]', 
      start: Ext.Date.clearTime(new Date()), 
      salary: 50000, 
      active: true 
     }); 

     var storeClassName = Ext.getClassName(store); 
     var tempStore = Ext.create(storeClassName, { buffered: false }); 
     tempStore.add(r); 
     tempStore.sync({ 
      success: function(args) { 
       // reload your grid and scroll to the position of the new record 
       // e.g. 
       store.data.clear(); 
       store.load({ 
         success: function() { 
          grid.view.bufferedRenderer.scrollTo(args.response.indexOfNewRecord, true); 
          rowEditing.startEdit(0, 0); 
         } 
       });      
      } 
     }); 
    } 
}], 

缺少的是索引的定义。我从我的web服务中获取同步响应,因此我可以滚动到总共数据集中的索引位置。

+0

如何将此商店与编辑网格? – 2013-06-17 11:26:57

+0

在Ext.grid.plugin.EditingView中有一个beforeeedit事件。也许你可以在这个事件中添加一个处理程序并在之前交换商店? – Christoph 2013-06-17 11:40:07

+0

为了清晰起见,你可以添加一些更多的代码吗?如前所述,我无法在插入之前更换商店。 – 2013-07-17 11:59:52

2

需要注意的一件事是,尽管创建无缓冲存储的解决方法在您可以通过代码执行时效果很好,但您仍有一些网格编辑元素无法获得此机会 - 例如,使用单元格或者在具有缓冲存储的网格上的行编辑插件不再适用于4.2。

最后,我们最终回到4.1重新获得缓冲存储功能,并将在再次升级之前监视未来ExtJS更新中会发生的情况。我建议任何人在大型远程数据库上使用缓冲存储(在页面加载过程中不能接受读取整个数据库),请仔细考虑4.2升级。

+0

他们在新版本中破坏现有功能确实很糟糕。这意味着如果我们想升级,我们需要重写很多代码。我也同意任何使用缓冲存储的人都应该远离4.2版本。 – 2013-07-30 05:16:13