' Close Add/Edit forms for jqgrid with afterSubmit function

I am newbie in using jqgrid.

I am using afterSubmit: function to reload the grid for add/edit changes,afterSubmit: function is working fine with updated data. But Add record and Edit forms are not getting closed. I have used this options (closeAfterEdit:true,closeAfterAdd:true) not getting closed. My problem with where exactly use this options confussing.

Without afterSubmit: function both forms are getting closed. Sorry! for my bad english. Please find the bellow navGrid code:

   $("#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});


Solution 1:[1]

which jqgrid verion are you using. I am using 3.6+, and this works for me

$("#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

        );

Solution 2:[2]

These are the arguments of the navGrid method:

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

To close the dialog windows both after edit and after add a row, you sholud add closeAfterEdit:true to the prmEdit, and closeAfterAdd:true to the prmAdd object. Like here:

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

Solution 3:[3]

the correct syntax for afterSubmit is:

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

Solution 4:[4]

This resolved the issue for me;

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

Solution 5:[5]

in fact it is very easy to do it , you just need to add one command line like as following code

closeAfterEdit:true

 $('#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) {
       //  }
    }

........

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Meenakshi
Solution 2 zbacsi
Solution 3 Yaqoob Al-Shuaibi
Solution 4 Irshad
Solution 5 Willie Cheng