[英]Toggle cell readonly / editable in jqGrid
I have I case where I want to toggle a cell to readonly / editable, depending on some condition.我遇到过我想根据某些条件将单元格切换为只读/可编辑的情况。 It almost works, I can make it readonly, but not editable again.
它几乎可以工作,我可以将其设置为只读,但不能再次编辑。
grid.setColProp("a", {
editoptions: {
value: data.opPadrag,
dataEvents: [{
type: 'change',
fn: function (e) {
var selr = grid.jqGrid('getGridParam', 'selrow');
if (someCondition) grid.jqGrid('setCell', selr, 'c', '', 'not-editable-cell');
else
// Problem here - how to make it editable. I've tried a few ways, none worked
// grid.jqGrid('setCell', selr, 'c', '', 'editable-cell');
// grid.jqGrid('setCell', selr, 'c', '', 'editable');
// grid.jqGrid('setCell', selr, 'c', '', '');
}
}]
}
});
Any ideas?有任何想法吗?
There is no built in function for removing class from cell, you can do this manually like this:没有内置 function 用于从单元格中删除 class,您可以像这样手动执行此操作:
grid.setColProp('a', { editoptions: { value: data.opPadrag, dataEvents: [{ type: 'change', fn: function (e) {
var selr = grid.jqGrid('getGridParam', 'selrow');
if (someCondition) {
grid.jqGrid('setCell', selr, 'c', '', 'not-editable-cell');
} else {
var colModel = grid.jqGrid('getGridParam', 'colModel');
for (var iCol = 0; iCol < colModel.length; iCol++) {
if (colModel[iCol].name === 'c') {
var row = grid[0].rows.namedItem(selr);
var cell = row.cells[iCol];
$(cell).removeClass('not-editable-cell');
break;
}
}
}
} }] } });
You can perform this action in more efficiency.您可以更有效地执行此操作。
Using jquery one line of code:使用 jquery 一行代码:
$("#<GridId> tr[id='<RowId>'] td[aria-describedby='<GridId>_<ColumnName>']").removeClass('not-editable-cell');
Example:例子:
$("#maingrid tr[id='1'] td[aria-describedby='maingrid_column1']").removeClass('not-editable-cell');
thanks,谢谢,
Gavriel加夫列尔
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.