I have this code just to send data from already loaded jqGrid:
jQuery("#bedata").click(function(){ //Function for button "bedata"
var postData = "SOME DATA TO SEND"
//Sending data:
$.ajax({
type: "POST";
url: "GuardaFila.action", //Action called to data treatament (Struts 2)
data : {
jgGridData: postData, //PARAMETER jgGrdData with variable "postData" value
customData: "someinfo" //Just another parameter called "customData" with more data,
},
dataType:"json",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
//Success function has the key that I am looking for:
success: function(response, textStatus, xhr) {
//SOME CODE HERE TO REFILL jqGrid.
alert("success");
},
error: function(xhr, textStatus, errorThrown) {
alert("error");
}
});
});
jqGrid has been created before this way:
jQuery("#rowed3").jqGrid({
url:'CargaTabla.action',
datatype: "json",
colNames:['id', 'Direccion', 'Nombre'],
colModel:[
{name:'id',index:'id', width:55},
{name:'direccion',index:'direccion', width:90, editable:true},
{name:'nombre',index:'nombre', width:100,editable:true}
],
jsonReader: {
root: 'gridModel',
id: '0',
cell :"",
repeatitems: false
},
(....... etc)
So, id for jqGrid table is #rowed3. I know that in the ajax function:
success: function(response, textStatus, xhr) {
//SOME CODE HERE TO REFILL jqGrid.
alert("success");
},
response parameter has a the new content in JSON for the grid. I tried some ways to refill the grid with its data as setting its “datastr” parameter with its content and others. Has someone faced before this problem?
Thank you.
Don’t reinvent the wheel here. jqGrid already knows how to fetch data, so you don’t need to call
$.ajax. Just change the grid params and tell it to do its thing (from memory; correct function names if need be, but this will give you the idea):