2012-04-10 541 views
0

我有我想切换单元格为只读/可编辑的情况,具体取决于某些条件。它几乎可以工作,我可以只读,但不能再编辑。在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', '', ''); 
      } 
     }] 
    } 
}); 

任何想法?

回答

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

小打字错误:'ICOL [ICOL] .name'应是'colModel [iCol] .name'。 – Oleg 2012-04-11 08:30:09

+0

修好了,谢谢。 – tpeczek 2012-04-11 09:04:49

+0

不客气! – Oleg 2012-04-11 19:51:43

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

相关问题