Rebooting jqgrid does not happen with loadonce: true

I am new to using jqgrid.

When loading a new page, the grid correctly loads data from the database. Subsequently, due to loadonce: true, the grid does not reload data from the database for adding / editing / deleting.

My application combination is JSP, Servlet, MySQL

I have a grid with the following settings

jQuery("#userList").jqGrid({
                    url: '<%=request.getContextPath()%>/userJqGrid?q=1&action=fetchData&userCookie=<%= encodedCookie%>',
                    datatype: 'xml',
                    mtype: 'GET',
                    colNames:['<%= userProp.getProperty(userColNames[0])%>',
                              '<%= userProp.getProperty(userColNames[1])%>',
                              '<%= userProp.getProperty(userColNames[2])%>',
                              '<%= userProp.getProperty(userColNames[3])%>',
                              '<%= userProp.getProperty(userColNames[4])%>',
                              '<%= userProp.getProperty(userColNames[5])%>'
],
                    colModel:[
                        {name:'<%= userColNames[0]%>',index:'<%= userColNames[0]%>',
                            width:120,sortable:true,editable:true,editrules:{required:true},formoptions:{rowpos:1, elmprefix:'*'}},
                        {name:'<%= userColNames[1]%>',index:'<%= userColNames[1]%>',
                            width:130,sortable:true,editable:true},
                        {name:'<%= userColNames[2]%>',index:'<%= userColNames[2]%>',
                            width:100,sortable:true,editable:true,editrules:{required:true},formoptions:{rowpos:3, elmprefix:'*'}},
                        {name:'<%= userColNames[3]%>',index:'<%= userColNames[3]%>',
                            width:180,sortable:true,editable:true,editrules:{email:true,required:true},formoptions:{rowpos:4, elmprefix:'*'}},
                        {name:'<%= userColNames[4]%>',index:'<%= userColNames[4]%>', 
                            width:100,sortable:true,editable:true},
                        {name:'<%= userColNames[5]%>',index:'<%= userColNames[5]%>', 
                            width:100,sortable:true,editable:true},
                    ],
                    pager: '#pager1',
                    rowNum:50,
                    height:'auto',
                    //rowList:[10,20,30],
                    loadonce: true,
                    sortname:'<%= userColNames[0]%>',
                    viewrecords: true,
                    editurl:'<%=request.getContextPath()%>/userJqGrid?q=1&action=addData&userCookie=<%= encodedCookie%>',
                    caption: 'User Grid',
                    ondblClickRow: function(rowid) {
                       $("#userList").jqGrid('editGridRow',rowid, userEditParam);
                        return;
                    }
                 });
$("#userList").jqGrid('navGrid',"#pager1",{add:true,edit:true,del:true});
$("#userList").jqGrid('gridResize', { minWidth: 450, minHeight: 150});

I tried adding the following code to reboot

$("#userList").jqGrid('setGridParam',{datatype:xml}).trigger('reloadGrid')

Can anyone help?

Solution that worked for me

$("#userList").jqGrid('navGrid',"#pager1",{add:true,edit:true,del:true,refresh:true,

beforeRefresh: function() {
   $("#userList").jqGrid('setGridParam',{datatype:xml}).trigger('reloadGrid');
}},
{
  afterSubmit: processAddEdit,
       closeAfterAdd:true,
       closeAfterEdit:true
},{
  aftersubmit:processAddEdit,
       closeAfterAdd:true,
       closeAfterEdit:true
});

function processAddEdit() {
  $("#userList").jqGrid('setGridParam',{datatype:xml}).trigger('reloadGrid');
  return[true,'']; //no error
}
+3
source share
3 answers

Right datatype:'xml', not datatype:xml. So the type code

$("#userList").jqGrid('setGridParam', {datatype:'xml'})
              .trigger('reloadGrid', [{page:1}]);

must work. See here for additional options reloadGrid.

. , , . , , " " . " " , , (. ). refresh: false navGrid, " ", navButtonAdd, , , , onClickButton:

var myGrid = $('#userList');
myGrid.jqGrid({
    datatype: 'xml',
    loadonce: true,
    pager: '#pager1',
    // ... other parameters which you use
});
myGrid.jqGrid('navGrid', '#pager1', {refresh: false});
myGrid.jqGrid(
    'navButtonAdd',
    '#pager1',
    {
        caption: "",
        buttonicon: "ui-icon-refresh",
        title: $.jgrid.nav.refreshtitle,
        onClickButton: function () {
            $(this).jqGrid('setGridParam', {datatype:'xml'});
            $(this).trigger('reloadGrid', [{page:1}]);
        }
    }
);

2. , afterSubmit, , reloadGrid, jqGrid.

myGrid.jqGrid('navGrid', '#pager1', {refresh: false},
    { // Edit options
        afterSubmit: function () {
            $(this).jqGrid('setGridParam', {datatype:'xml'});
            return [true,'']; // no error
        }
    },
    { // Add options
        afterSubmit: function () {
            $(this).jqGrid('setGridParam', {datatype:'xml'});
            return [true,'',false]; // no error and no new rowid
        }
    },
    { // Delete options
        afterSubmit: function () {
            $(this).jqGrid('setGridParam', {datatype:'xml'});
            return [true,'']; // no error
        }
    }
);

, , , . reloadAfterSubmit: false . . .

+9

,

        $("#list1").jqGrid('navGrid', '#pager1', {refresh: false},
{ // Edit options
    afterSubmit: function () {$(this).jqGrid('setGridParam', {datatype:'xml'});
        return [true,'']; // no error
    }
},
{ // Add options
    afterSubmit: function () {
        $(this).jqGrid('setGridParam', {datatype:'xml'});
        return [true,'',false]; // no error and no new rowid
    }
},
{ // Delete options
    afterSubmit: function () {
        $(this).jqGrid('setGridParam', {datatype:'xml'});
        return [true,'']; // no error
    }
});  jQuery("#list1").jqGrid('navGrid','#pager1',{edit:true,add:true,del:true,view:false},{url: "product.php" },{closeAfterEdit: true,closeAfterAdd: true});
       jQuery("#list1").jqGrid('gridResize',{minWidth:350,maxWidth:850,minHeight:80, maxHeight:350}).trigger('reloadGrid');
       $('#list1').jqGrid('setGridParam', {datatype:'xml'});
       $('#list1').trigger('reloadGrid', [{page:1}]);

. .

0
{
    // edit options
    zIndex: 100,
    url: '/User/Edit',
    closeOnEscape: true,
    closeAfterEdit: true,
    recreateForm: true,

    afterComplete: function (response) {
        if (response.responseText) {
            $("#userGrid").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
        }
    }
}

Worked for me:

Logic: we reload the grid again after the call returns to JqGrid .... try this working

0
source

All Articles