I am newbie in using jqgrid.
While new page load the grid is properly loading the data from database. Afterwards due to loadonce: true the grid is not reloading the data from database for add/edit/delete.
My application combination is JSP, Servlet, MySQL
I have a grid with 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 following code to reload
$("#userList").jqGrid('setGridParam',{datatype:xml}).trigger('reloadGrid')
Can some one help?
Solution which 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
}
See Question&Answers more detail:
os