Reputation: 53
I want to send row data to be updated but when the jqgrid was created the datatype set to "Local". I'm trying to set the dataType : "json" in onSubmiClick and want to send the row data (data to be posted to REST method). Here is my JqGrid code block. Any help is appreciated.
var editSettings = {
recreateForm:true,
jqModal:false,
reloadAfterSubmit:true,
closeOnEscape:true,
closeAfterEdit:true,
addCaption: "Edit Scripts",
onclickSubmit: function(params,postdata) {
$.ajax({
type : "POST",
url : "/fnol-maintenance/reports/update",
contentType : "application/json; charset=utf-8",
data : {
jqGridData : postdata //I'm trying to figure out how to pass the row data being edited using jQgrid Form Edit.
},
dataType : "json",
asynch : false
});
return{};
}};
myGrid = $("#mygrid").jqGrid({
caption: "FNOL Maintenance Report",
datatype: "local",
colNames: myColNames,
colModel: myColModel,
pager: '#mypager',
//rowNum: 10000,
rowList: [10, 20, 50, 100],
viewrecords: true,
autowidth: true,
gridview: true,
ignorecase: true,
altRows: true,
altclass: 'myAltRowClass',
height: gridHeight, //commented to use browser vertical scrollbar
//height: "100%", //un-commented to use browser vertical scrollbar
loadtext: "Loading data...",
//forceFit: true
//headertitles: true,
footerrow: true,
userDataOnFooter: true,
editUrl: '/fnol-maintenance/reports/update'
});
myGrid.jqGrid('navGrid','#mypager',{edit:true,add:false,del:false,search:false}, editSettings );
jQuery("#mygrid").jqGrid('setCaption', (myjsongrid.reportTitle==""?'Maintenance Report':myjsongrid.reportTitle));
myGrid.setGridParam({datatype: "local"});
myGrid.setGridParam({data: mydata}).trigger("reloadGrid");
//jQuery("#mygrid").jqGrid('navGrid','#mypager',{del:false,add:false,edit:true,search:false});
//alert("after ajax");
Upvotes: 0
Views: 1749
Reputation: 221997
The code which you posted is very strange. First of all you use undefined variable editSettings
. The value will be assigned to editSettings
later. One should not wonder that callback onclickSubmit
will be not called.
In the same way I don't see where you defined myGrid
, mydata
etc. Is it real code which you use?
By the way I see no sense to create jqGrid without specifying of data
parameter and then to use setGridParam
to set datatype
to "local" (it was already "local"), change data
parameter and reload grid. One can just use data: mydata
parameter directly during creating the grid.
I don't see any sense to use $.ajax
inside of onclickSubmit
to post the data manually to the server because jqGrid do the same internally. If you need some custom serialization of data which will be sent to the server you can use serializeEditData callback. If you need just set some additional options of $.ajax
(like contentType
) you can use ajaxEditOptions option.
Upvotes: 2