2012-04-10 102 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

相關問題