Ext-JS:如何禁用网格中单个单元格的单元格编辑? [英] Ext-JS: How to disable cell editing for individual cells in a grid?
问题描述
要使网格可编辑,我遵循API文档并使用以下内容:
selType:'cellmodel' ,
plugins:[
Ext.create('Ext.grid.plugin.CellEditing',{
clicksToEdit:2
})
]
但是,对于这个网格,有几个不应该更改的单元格。
我可以简单地让事件处理程序在网格中更改数据后恢复到正确的状态,但这似乎是恶作剧,难以维护和无法读取。有没有更好的办法呢?我读了API,但找不到任何有用的属性。
更新
As对于这个特定的应用程序,只需禁用第一行即可。但是我也有兴趣选择几个网格,使它们不可编辑(想象一个带网格的Sudoku游戏)。
我已经从您想要使第一行不可编辑的评论中了解到。有丑陋但快速的解决方案。分配给你的插件 beforeedit
处理程序。当事件被触发时,检查正在编辑的行。如果首先 - 返回false
:
插件:[
Ext.create('Ext.grid.plugin.CellEditing',{
clicksToEdit:2,
listeners:{
beforeedit:function(e,editor){
if(e .rowIdx == 0)
return false;
}
}
})
]
查看 beforeedit 。
更新的事件 - beforeeditrel =noreferrer> docs
文档说, beforeedit
有这样的参数集:
beforeedit(Ext.grid.plugin.Editing editor,Object e,Object options)
但是有错误。正确的顺序是:
beforeedit(Object e,Ext.grid.plugin.Editing editor,Object options)
由于这个事实,我更新了一个例子。
I am now building a web application with Ext-JS 4.0.2, and I am using a editable grid to control the data to be shown for a table on the same page.
To make the grid editable, I followed the API documentation and used the following:
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
})
]
However, for this grid, there are several cells that are not supposed to be changed.
I could simply let the event handler change the data back to the right state once it is changed in the grid, but this seems to be hacky, hard to maintain, and unreadable. Is there any better way to do this? I read the API but cannot find any useful attributes.
UPDATE
As for this particular app, just disable the first row would work. But I am also interested in choose several grid and make them not editable (imagine a Sudoku game with a grid).
As I've understand from comments you want to make first row not editable. There is ugly but quick solution. Assign to your plugin beforeedit
handler. And when event is being fired check what row is being edited. If first - return false
:
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2,
listeners: {
beforeedit: function(e, editor){
if (e.rowIdx == 0)
return false;
}
}
})
]
Check out docs for beforeedit
.
UPDATE
Docs say that beforeedit
has such set of params:
beforeedit( Ext.grid.plugin.Editing editor, Object e, Object options )
But there is mistake. The correct sequance is:
beforeedit( Object e, Ext.grid.plugin.Editing editor, Object options )
I've updated example due to this fact.
这篇关于Ext-JS:如何禁用网格中单个单元格的单元格编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!