how to load the new added data in jqgrid
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 = 开发者_StackOverflow中文版{
"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 of success
handle of $.ajax
call of your update
function. 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:true
parameter which change the original value of the datatype
parameter of the jqGrid to datatype:'local'
. If you use loadonce:true
and need to reload the data from the server you have to reset the datatype
parameter 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 the datatype
you can use setGridParam
method of jqGrid.
精彩评论