我刚开始使用dojo,刚开始玩弄它。基本上我想要做的是我有一个表有2列A和B.列B中的单元格将根据列A的值锁定或可编辑。动态控制dojo DataGrid列的编辑模式
有没有办法设置可编辑属性在单元级而不是在布局中定义的列级别?
我尝试使用格式化程序,但无法使其正常工作。
我刚开始使用dojo,刚开始玩弄它。基本上我想要做的是我有一个表有2列A和B.列B中的单元格将根据列A的值锁定或可编辑。动态控制dojo DataGrid列的编辑模式
有没有办法设置可编辑属性在单元级而不是在布局中定义的列级别?
我尝试使用格式化程序,但无法使其正常工作。
您可以覆盖网格功能onCellDblClick
- 但这是特定于版本的代码。如果dojo.version在您的页面中发生变化,则网格Event.js可能会有其他行为。以下片段摘自... /dojox/grid/_Event.js版本1.7.2。
如果您编辑设置通过双击单元格(默认行为)解雇,你可以选择简单地用下面的有利地位return
忽略它:
var customOnEditActivate = function(e){
// summary:
// Event fired when a cell is double-clicked.
// e: Event
// Decorated event object contains reference to grid, cell, and rowIndex
var event;
if(this._click.length > 1 && has('ie')){
event = this._click[1];
}else if(this._click.length > 1 && this._click[0].rowIndex != this._click[1].rowIndex){
event = this._click[0];
}else{
event = e;
}
////
// entrypoints of interest: event.cell & event.cellNode(.innerHTML)
// As example we could ignore editing mode if cell contains 'NON_EDITABLE'
if(cell.innerHTML.match("NON_EDITABLE"))
return;
//
////
this.focus.setFocusCell(event.cell, event.rowIndex);
this.onRowClick(event);
this.edit.setEditCell(event.cell, event.rowIndex);
this.onRowDblClick(e);
},
因此,虽然初始化网格设置的配置参数onCellDblClick
上述功能:
require(["dojox/grid/DataGrid"], function(DataGrid) {
var grid = new DataGrid({
onCellDblClick: customOnEditActivate
});
});
或
<div
data-dojo-type="dojox.grid.DataGrid"
data-dojo-props="onCellDblClick: customOnEditActivate"
></div>
感谢您的帮助。当我回到家时,我会试试这个。 – byteme
你可以重写DataGrid的
canEdit: function(inCell, inRowIndex)
方法。从这一点,你可以得到的项目:
this.getItem(inRowIndex)
然后制定出它是否应该为可编辑与否,并返回真/假。
我得到了以下的工作(类似埃德Jellard的建议):
<script type="dojo/require">
jsonRestStore : "dojox/data/JsonRestStore",
contentPane : "dijit/layout/ContentPane",
dataGrid : "dojox/grid/DataGrid"
</script>
<div dojoType="dijit.layout.ContentPane">
<script type="dojo/method">
configStore = new dojox.data.JsonRestStore
({ target : "/data/config",
idAttribute : "propertyName" });
configStructure =
[ {field:'propertyName', name:'Property - Name',
width:20},
{field:'value', name:'Value',
editable:true},
{field:'guiConfigurable', name:'Property Type'},
{field:'description', name:'Description'}
];
</script>
</div>
<table data-dojo-type="dojox.grid.DataGrid"
store="configStore"
structure=configStructure>
<script type="dojo/method" event="canSort" args="sortInfo">
return false;
</script>
<script type="dojo/method" event="onApplyCellEdit" >
configStore.save();
</script>
<script type="dojo/method" event="canEdit" args="inCell, inRowIndex">
var gc = this.getItem(inRowIndex).guiConfigurable;
return gc == 'W' || gc == 'D';
</script>
<tbody/>
</table>
这是相当艰巨的任务。我也尝试了很多东西,不得不按照不同的方法编辑单元格。您可以通过捕获onApplyCellEdit来避免单元格更新,但将单元格锁定为不可编辑不是一项简单的任务。 – Sandeep