Hi I am a newbie to jqGrid. I am using jqGrid 4.4. I have successfully used the approach by Oleg in
Adding new row to jqGrid using modal form on client only
to add rows locally. There are 2 issues I am facing
- The row that is not added to the end , how can I achieve this?
- I send all the rows on click of a button as below:
I always get the alert in the error block?
$("#sendButton").click(function(){
var gridData = jQuery("#list").getRowData();
var myJSONString = JSON.stringify(gridData);
var postData = myJSONString.replace(/[\"]/g, '\"');
alert("JSON serialized jqGrid data:\n" + postData);
$.ajax({
type: "POST",
url: CONTEXT_ROOT+"/json",
data : postData,
dataType:"json",
contentType: "application/json; charset=utf-8",
success: function(response, textStatus, xhr) {
alert("success");
},
error: function(xhr, textStatus, errorThrown) {
alert("error:"+errorThrown+" textStatus : "+textStatus);
}
});
});
Not sure what I need to return once I save in the java controller. Here is the code in the controller. I also tried with the return as void but same result. Also is there a better approach to bind the list of json objects coming from the jsp to a list of domain objects. I have tried Binding when there is only a single object like from the form using @RequestBody as explained in
http://blog.springsource.org/2010/01/25/ajax-simplifications-in-spring-3-0/
@RequestMapping(value = "/json", method = RequestMethod.POST)
public ModelAndView saveNewCasePackOptions(@RequestBody List<Map> json) {
for(Map mJson : json){
String idCasePkOptions = (String)mJson.get("idCasePackOptions");
Long idCasePackOptions = (idCasePkOptions.isEmpty())?null:new Long(idCasePkOptions);
Short cypharecommended = new Short((String)mJson.get("cypharecommended"));
Short distributorapproved = new Short((String)mJson.get("distributorapproved"));
String heightStr = (String)mJson.get("height");
Double height = (heightStr.isEmpty())?null:new Double(heightStr);
String lengthStr = (String)mJson.get("length");
Double length = (lengthStr.isEmpty())?null:new Double(lengthStr);
String weightStr = (String)mJson.get("height");
Double weight = (weightStr.isEmpty())?null:new Double(weightStr);
String widthStr = (String)mJson.get("width");
Double width = (widthStr.isEmpty())?null:new Double(widthStr);
String stateString = (String)mJson.get("statuscode");
stateString = (stateString.contains("Green"))?"1":"0";
Short statuscode = new Short(stateString);
CasePackOptions casePkOpt = new CasePackOptions(idCasePackOptions, cypharecommended, distributorapproved, height, length, statuscode, weight, width);
System.out.println(casePkOpt);
casePackOptionsService.save(casePkOpt);
}
ModelAndView mav = new ModelAndView();
mav.setViewName("casepackoptions/listPage1.jsp");
return mav;
}
Any help will be much appreciated.