i know this sounds simple for some people out there. i also tried this one. but for some reason, i really can’t refresh and view my newly added, edited and deleted in jqgrid.
i am making a button in my program that would add, edit and delete and after that, it will refresh my jqgrid and display what ever change i’ve made in their. for example, i added new data,. in first attempt, it will display the newly added data but in the second time around, it wont show anymore. my edit and delete data won’t refresh also. here’s the code:
function Edit(){
var selected = $("#list1").jqGrid('getGridParam', 'selrow');
var dat = {
"ID": 'xyz',
...
"keyFields": [{"..."}]
};
update(dat);
$('#list1').trigger('reloadGrid');
}
function update(dat){
$.ajax({
type: 'GET',
url: 'mydata.php?' + $.param({path:'this/update',json:JSON.stringify(dat)}),
dataType: Settings.ajaxDataType,
success: function(data) {
if ('error' in data)
{
alert('ERROR']);
}
}
});
}
the server side is ok and updated whatever i do in the screen. when i first do this with add button only, there’s no problem at all. problem came up only after my edit and delete button. hope someone can help me understand this.
You don’t posted any definition of the jqGrid which you use, so I can say only what is wrong in the code which you posted.
First problem is that you have to place
$('#list1').trigger('reloadGrid');line inside ofsuccesshandle of$.ajaxcall of yourupdatefunction. Only after the data are successfully updated on the server you should trigger grid reload.The second possible problem you can have if you use
loadonce:trueparameter which change the original value of thedatatypeparameter of the jqGrid todatatype:'local'. If you useloadonce:trueand need to reload the data from the server you have to reset thedatatypeparameter of the jqGrid to its initial value (‘xml’ or ‘json’ depend on what you use) and only then reload grid with respect of ‘reloadGrid’. To change thedatatypeyou can usesetGridParammethod of jqGrid.