在捕获 beforeCellEdit 事件时,是否可以以某种方式阻止单元格进入编辑模式?
beforeEditCell: function (rowid, cellname, value, irow, icol) {
if (cellname != 'aSpecificCol')
return;
var grid = $("#grid");
if (aCondition == "something")
grid.setColProp('aSpecificCol', { editable: false });
else
grid.setColProp('aSpecificCol', { editable: true });
}
事件触发,但列属性的设置似乎没有更改编辑模式。
最佳答案
方法beforeEditCell
将在编辑过程中被调用。它的存在主要是为了在新创建的输入或选择元素中进行一些初始化。
如果您需要防止某些单元格在单元格编辑模式下进行编辑,我建议您有时之前在单元格中设置 "not-editable-cell"
类(例如在 cellattr
或在 loadComplete
中)或使用 beforeSelectRow
为某些单元格返回 false
。 beforeSelectRow
返回 false 单元格将不会被编辑。
beforeSelectRow: function (rowid, e) {
var $td = $(e.target).closest("td"), iCol = $.jgrid.getCellIndex($td[0]);
if (/* test some rules here */) {
return false; // prevent selection and so the editing of the cell
}
}
关于javascript - 使用 beforeCellEdit 事件阻止 jqGrid 进入编辑单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10104251/