2011-08-17 120 views
1

我使用jqGrid的新手。關閉了jqGrid的添加/編輯形式與afterSubmit功能

我使用afterSubmit:函數重載用於添加/編輯修改,afterSubmit電網:功能工作正常使用更新的數據。但是添加記錄和編輯表單沒有關閉。 我已經使用這個選項(closeAfterEdit:真,closeAfterAdd:真)沒有得到關閉。 我的問題在哪裏確切地使用這個選項confussing。

沒有afterSubmit:功能兩種形式越來越封閉。 對不起!因爲我的英語不好。 請在下面找到navGrid代碼:

$("#companyList").jqGrid('navGrid',"#pager2",{add:true,edit:true,del:true,refresh:false, 
        beforeRefresh: function(){ 
         $("#companyList").jqGrid('setGridParam',{datatype:'xml'}).trigger('reloadGrid'); 
        }}, 
        { 
        afterSubmit: function() { 
         $("#companyList").jqGrid('setGridParam'{datatype:'xml'}).trigger('reloadGrid'); 
         return [true,'',false]; // no error and no new rowid 
         } 
        },{ 
         afterSubmit: function() { 
          $("#companyList").jqGrid('setGridParam',{datatype:'xml'}).trigger('reloadGrid'); 
         return [true,'']; // no error 
         } 
        }, 
        editParam = { 
         editData:{myparam:function(){return "myval";}}, 
         reloadAfterSubmit: true, 
         editCaption:'Edit Record', 
         bSubmit:'Save', 
         url:'<%=request.getContextPath()%>/CompanyJqGrid? q=1&action=addData', 
         closeAfterEdit:true, 
         viewPagerButtons:false 
        },{closeAfterAdd:true}); 

回答

0

您正在使用哪個jqgrid verion。我使用3.6及更高版本,這對我的作品

$("#gUserGrid").jqGrid('navGrid','#pagergUserGrid',{add:true,edit:true,del:true,search:true}, //NAVIGATION BAR 
     { 
      jqModal:true, 
      savekey: [true,13], 
      navkeys: [true,38,40], 
      width: 500, 
      reloadAfterSubmit:true 


     }, // edit options 
     { jqModal:true 
      ,reloadAfterSubmit:true 

     }, // add options 
     { 
         reloadAfterSubmit:true}, //del options 
     { 
     } // search options 

     ); 
0

這些都是navGrid方法的參數:

.navGrid('#gridpager',{parameters}, prmEdit, prmAdd, prmDel, prmSearch, prmView); 

到兩個編輯後關閉對話窗口,並添加一行後,你sholud將closeAfterEdit:true添加到prmEdit,並將closeAfterAdd:true添加到prmAdd對象。 喜歡這裏:

$("#companyList").jqGrid('navGrid',"#pager2",{add:true,edit:true,del:true,refresh:false, 
     beforeRefresh: function(){...}}, 
    {//prmEdit 
     closeAfterEdit:true, 
     afterSubmit: function() {...} 
    }, 
    {//prmAdd 
     closeAfterAdd:true, 
     afterSubmit: function() {...} 
    } 
) 
0

正確的語法afterSubmit是:

afterSubmit : function(response, postdata) 
{ 
    … 
    return [success,message,new_id] 
} 
0

這解決了這個問題對我來說;

afterSubmit: function (resp, postdata) 
{ 
    return [true,"",null]; 
}, closeAfterEdit: true 
0

其實這是很容易做到這一點,你只需要一個命令行中添加類似如下的代碼

closeAfterEdit:真

$('#jQGridDemo').jqGrid('navGrid', '#jQGridDemoPager', 
    { 
     edit: true, 
     add: false, 
     del: false, 
     search: false, 
    }, 
    { //EDIT 
     closeOnEscape: true,//Closes the popup on pressing escape key 
     closeAfterEdit: true, 
     //afterSubmit: function (response, postdata) { 
     // } 
    } 

... .....