2013-01-08 99 views
0

我正在開發一個使用JSP的Web應用程序& Servlet(IDE:Eclipse,Database:Oracle10)。jqgrid:添加行

我正在使用JQGRID以表格格式顯示數據。我還希望在JQGRID中添加,編輯,刪除功能。到目前爲止,我已完成編輯,刪除功能。

現在我想添加的功能,問題是,當我在默認點擊Add按鈕則顯示我只DESCRIPTION被設置editable:true領域,尚未出現其他兩個領域這是不可編輯的。我沒有設置它們是可編輯的,因爲它們是主鍵,我不希望它們被編輯。

所以我的問題是有沒有什麼辦法,我可以設置不可編輯的列編輯後用戶點擊添加。

以下是我的源代碼:

jQuery("#list10_d2").jqGrid({ 
       height: "100%", 
       url:'ProtocolJGridServChildStages?q=2&action=protStages', 
       datatype: "xml", 
       colNames:['Sr. No.','PROTOCOL_ID', 'STAGE_ID', 'DESCRIPTION'], 
       colModel:[{name:'srNo',index:'srNo', width:35,sortable:true}, 
          {name:'PROTOCOL_ID',index:'PROTOCOL_ID', width:100,sortable:false}, 
          {name:'STAGE_ID',index:'STAGE_ID', width:100,sortable:false}, 
          {name:'DESCRIPTION',index:'DESCRIPTION', width:150,sortable:false,editable:true} 
          ], 
       rowNum:5, 
       rowList:[2,4,10], 
       pager: '#pager10_d2', 
       sortname: 'PROTOCOL_ID', 
       viewrecords: true, 
       sortorder: "asc", 
       multiselect: true, 
       editurl: "ProtocolJGridServChildStages?action=protocolStageEdit", 
       caption:"CRM_PROT_STAGES", 
       onSelectRow: function(ids) 
       { 
        if(ids && ids!==lastsel) 
        {    
         var ret = jQuery("#list10_d2").jqGrid('getRowData',ids); 
         protID = ret.PROTOCOL_ID; 
         stageID = ret.STAGE_ID; 

         jQuery("#list10_d2").jqGrid('setGridParam',{editurl:'ProtocolJGridServChildStages?action=protocolStageEdit&protID='+protID+'&stageID='+stageID}); 
         jQuery('#list10_d2').jqGrid('restoreRow',lastsel); 
         jQuery('#list10_d2').jqGrid('editRow',ids,true); 
         lastsel=ids; 
        } 
       } 
      }).navGrid('#pager10_d2',{add:true,edit:true,del:true},{width:400,height:200},{width:500,mtype:'POST', url: 'ProtocolJGridServChildStages', addData:{action:'protocolStageAdd',protID: function() {return protID;}, stageID: function(){return stageID;}}, closeOnSubmit: true},{mtype: 'POST',url: 'ProtocolJGridServChildStages',delData: {action: 'protocolStageDelete',protID: function() {return protID;}, stageID: function(){return stageID;}}}); 
      jQuery("#ms1").click(function() { 
       var s; 
       s = jQuery("#list10_d2").jqGrid('getGridParam','selarrrow'); 
       alert(s); 
      }).navGrid('#page',{edit:true,add:true,del:true}); 

在此先感謝...

編輯:

.navGrid('#pager10_d2',{add:true,edit:true,del:true},{width:400,height:200},{width:500,mtype:'POST', url: 'ProtocolJGridServChildStages',beforeShowForm: function(){var cm = $('#list10_d2').jqGrid('getColProp',"PROTOCOL_ID"); cm.editable=true; cm = $('#list10_d2').jqGrid('getColProp',"STAGE_ID"); cm.editable=true; alert("before");}, addData:{action:'protocolStageAdd',protID: function() {return protID;}, stageID: function(){return stageID;}}, closeOnSubmit: true},{mtype: 'POST',url: 'ProtocolJGridServChildStages',delData: {action: 'protocolStageDelete',protID: function() {return protID;}, stageID: function(){return stageID;}}}); 

編輯

}).navGrid('#pager10_d2',{add:true,edit:true,del:true}, 
        {closeOnEscape:true, recreateForm: true, width:400,height:200}, 
        {closeOnEscape:true, recreateForm: true, beforeShowForm: function(formId){var cm = $('#list10_d2').jqGrid('getColProp',"PROTOCOL_ID"); cm.editable=false; var cm2 = $('#list10_d2').jqGrid('getColProp',"STAGE_ID"); cm2.editable=true; alert("before");}, addData:{action:'protocolStageAdd',protID: function() {return protID;}, stageID: function(){return stageID;}},width:500,mtype:'POST', url: 'ProtocolJGridServChildStages',closeOnSubmit: true}, 
        {closeOnEscape:true, recreateForm: true, mtype: 'POST',url: 'ProtocolJGridServChildStages',delData: {action: 'protocolStageDelete',protID: function() {return protID;}, stageID: function(){return stageID;}}}); 

回答

1

試試這個

在beforeShowForm事件

添加以下代碼

var cm = $('#list10_d2').jqGrid('getColProp',"PROTOCOL_ID"); 

裏面添加選項

{ cm.editable=true;} 

裏面添加選項

{cm.editable=false; } 
+0

我已編輯的代碼並添加beforeShowForm事件,但現在的問題是,我可以從行編輯列,但不能從'form',我想主鍵當我點擊導航欄上的添加按鈕時,列可以編輯。任何解決方案 – Bhushan

+0

http://stackoverflow.com/questions/3405029/jqgrid-disable-form-fields-when-editing/3405961#3405961 – Kris

+0

上述鏈接中的解決方案隱藏輸入框。在beforeShowForn 1中有一些問題。函數中缺少formId參數。 2.最初的輸入應該是可編輯的3.我認爲你需要添加recreateForm:true – Kris

1

使用點擊功能裏面以下

$("#list10_d2").jqGrid('setCell',rowid,cellname, '', {editable:true}); 

list10_d2.trigger("reloadGrid"); 
+0

謝謝回答 – Bhushan