2

在捕捉事件 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 });
 }

事件触发,但列属性的设置似乎没有改变编辑模式。

4

2 回答 2

7

The method beforeEditCell will be called in the middle of the editing process. It exist mostly to make some initialization in the new created input or select element.

If you need prevent some cells from editing in the cell editing mode I cen suggest you either to set "not-editable-cell" class in the cell sometimes before (for example in cellattr or in loadComplete) or use beforeSelectRow to return false for some cells. It beforeSelectRow return false the cell will be not editing.

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
    }
}
于 2012-04-17T08:04:24.533 回答
0

是的,您需要找到另一种选择,因为beforeEditCell仅提供一种在编辑单元格之前执行更多代码的方法。来自grid.celledit.js

if ($.isFunction($t.p.beforeEditCell)) {
    $t.p.beforeEditCell.call($t, $t.rows[iRow].id,nm,tmp,iRow,iCol);
}

但是,您似乎应该能够调用restoreCell以防止编辑模式:

恢复单元格

iRow, iCol

使用索引列 iCol 中的行索引 iRow(不要与 rowid 混合)恢复单元格的编辑内容

例如:

beforeEditCell: function (rowid, cellname, value, irow, icol) {
    var grid = $("#grid");
    if (cellname != 'aSpecificCol') {
        grid.jqGrid("restoreCell", irow, icol);
        return;
    }

如果这不起作用,您可以尝试将此代码添加到afterEditCell事件中,这可能是更合适的位置。

于 2012-04-11T13:43:55.860 回答