在jqGrid中切换单元格readonly / editable

时间:2012-04-10 13:16:48

标签: javascript jquery jqgrid

我有我想要将单元格切换为只读/可编辑的情况,具体取决于某些条件。它几乎可以工作,我可以只读它,但不能再编辑。

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', '', '');
            }
        }]
    }
});

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

没有用于从单元格中删除类的内置函数,您可以像这样手动执行此操作:

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;             
            }
        }
    }
} }] } }); 

答案 1 :(得分:0)

您可以更有效地执行此操作。

使用jquery一行代码:

 $("#<GridId> tr[id='<RowId>'] td[aria-describedby='<GridId>_<ColumnName>']").removeClass('not-editable-cell');

示例:

$("#maingrid tr[id='1'] td[aria-describedby='maingrid_column1']").removeClass('not-editable-cell');

感谢,

Gavriel