2012-02-10 156 views
0

如何在雙擊時使單元格不可編輯?單擊即可編輯單元格 。如何在雙擊時禁用單元格可編輯選項

我已經做單元格編輯啓用使用下面的代碼:

jQuery("#tree").jqGrid({ 
       url:'json/jsonSamplePots.json', 
       datatype: "json", 
       mtype:'GET', 
       colNames: ["Task id", "Task no.", "Task name", "Priority", "Start", "End", "Effort(hrs)", "Actual start", "Actual end", "Actual effort(hrs)", "Baseline start", "Baseline end", "Baseline effort(hrs)", "Task type", "Link", "Resources", "Tag"], 
       colModel: [ 
        {name:'id',width: 30, editable:false, align:"right",sortable:false, hidden: true, key: true}, 
        {name:'no',width:80, editable:false, align:"left", sortable:true, sorttype:"int"}, 
        {name:'name', width:150, editable:true, sortable:true, sorttype:"text"}, 
        {name:'priority', width:80, editable:true, align:"right", sortable:true, sorttype:"int"}, 
        {name:'sDate', width:80, editable:true, align:"right", sortable:true, sorttype:"date"}, 
        {name:'eDate', width:80, editable:true, align:"right", sortable:true, sorttype:"date"}, 
        {name:'effort', width:80, editable:true, align:"right", sortable:true, sorttype:"int"}, 
        {name:'asDate', width:80, editable:true, align:"right", sortable:true, sorttype:"date"}, 
        {name:'aeDate', width:80, editable:true, align:"right", sortable:true, sorttype:"date"}, 
        {name:'aeffort', width:80, editable:true, align:"right", sortable:true, sorttype:"int"}, 
        {name:'bsDate', width:80, editable:true, align:"right", sortable:true, sorttype:"date"}, 
        {name:'beDate', width:80, editable:true, align:"right", sortable:true, sorttype:"date"}, 
        {name:'beffort', width:80, editable:true, align:"right", sortable:true, sorttype:"int"}, 
        {name:'type', width:120, editable:true, align:"left", sortable:true, sorttype:"text"}, 
        {name:'link', width:80, editable:true, align:"left", sortable:true, sorttype:"text"}, 
        {name:'resources', width:300, editable:true, align:"left", sortable:true, sorttype:"int"}, 
        {name:'ref', width:80, editable:true, align:"right", sortable:true, sorttype:"int"}, 
       ], 
       rowNum:10, 
       rowList:[10,20,30], 
       pager: '#pcolch', 
       sortname: 'no', 
       treeGridModel:'adjacency', 
       autowidth:false, 
       sortorder: 'desc', 
       caption:"<a href="#">Task</a> 
       toolbar:[true,"top"], 
       treeGrid: true, 
       cellEdit: true, 
       sortable: true, 
       shrinkToFit :true, 
       //viewrecords: true, 
       height:'auto', 
       ExpandColumn:'name', 
       cellsubmit : 'clientArray', 

回答

1

我建議使用行編輯,而不是cellediting。我一直在掙扎一段時間,但單元編輯並不像行編輯那樣靈活。通過行編輯,您可以實現與單元編輯完全相同的目標。

您可以使用onCellSelect事件來啓用「單元格編輯」(行編輯)並使用事件參數來捕獲事件是否是雙擊事件。我用我自己的項目類似的東西:上面

'onCellSelect' : function(rowId, iCol, cellcontent, e) { 
    if(rowId && rowId !== lastsel && e.type != 'onDblClick') { 
    $('#resultsgrid').jqGrid(
     'saveRow', 
     lastsel, 
     null, 
     'clientArray', 
     null, 
     saveEditRow 
    ); 

    $('#resultsgrid').jqGrid('restoreRow', lastsel); 
    $('#resultsgrid').jqGrid('editRow', rowId, false); 

    lastsel = rowId; 
    } 
} 

注意僅僅是一個例子,你proberly不能複製/粘貼在自己的項目中使用它。你應該測試它是否適合你。

不是說onCellSelect不能在celledit模式下工作。

希望它可以幫助你!

相關問題