我想通过以下方式禁用datagrid中的特定行:
1)用不同的颜色突出显示一行
2)禁用该行的复选框/单选按钮选择
3)禁用对该行中存在的单元格的内联编辑,但允许对其他行进行内联编辑。
请给我。如果你有任何想法,请帮助我。
发布于 2012-08-30 01:43:41
您可以组合使用以下函数来提取内容
// as example, one of youre items uses identifier:'id' and 'id:10'
var identifier = '10';
var item = store._arrayOfTopLevelItems[10]; // you probably have this allready
var index = grid.getItemIndex(item); // find which index it has in grid
var rowNode = grid.getRowNode(index); // find a DOM element at that index
您将拥有作为rowNode
的<div>
,它包含一个包含单元格的表(与您获得的列数一样多)。设置其background-color
checkbox这件事,你可以很清楚地知道它有哪个单元格索引
var cellNode = dojo.query('td[idx='+cellIndex+']', rowNode)[0];
// with cellType Bool, td contains an input
var checkbox = cellNode.firstChild;
编辑其实是另一家商店..在焦点处理程序中工作。要覆盖它,你必须像一个数组一样保存你不想要编辑的行(所有的都是cell.editable == true
)。
function inarray(arr, testVal) {
return dojo.some(arr, function(val) { return val == testVal }).length > 0
}
grid.setNonEditable = function (rowIndex) {
if(! inarray(this.nonEditable,rowIndex) )
this.nonEditable.push(rowIndex);
}
grid.setEditable = function (rowIndex) {
this.nonEditable = dojo.filter(this.nonEditable, function(val) { return val != rowIndex; });
}
var originalApply = grid.onApplyEdit
grid.onApplyEdit = function(inValue, inRowIndex) {
if(! inarray(this.nonEditable,inRowIndex) )
originalApply.apply(this, arguments);
}
发布于 2014-04-30 17:04:48
如果您使用的是dojox.grid.DataGrid,则可以使用canEdit函数禁用行编辑或单元格编辑:
grid = new dojox.grid.DataGrid({
canEdit: function(inCell, inRowIndex) {
var item = this.getItem(inRowIndex);
var value = this.store.getValue(item, "name");
return value == null; // allow edit if value is null
}
}
https://stackoverflow.com/questions/12110648
复制相似问题