Uncaught TypeError: Cannot read property '0' from undefined - in jqGrid Spring MVC
I got the message: Uncaught TypeError: Can't read property '0' from undefined in jqGrid.min.js. When I post refresh data from grid.
my script:
$('#list-student').jqGrid({
url: 'GetAllStudent',
datatype: 'json',
colNames:['ID','Student', 'Birth day', 'Is Male ?','Province'],
colModel:[
{name:'id',index:'id', editable:false,width:100, align:'center'},
{name:'name',index:'name',editable:true, width:240},
{
name:'birth',
index:'birth',
editable:true,
width:200,
align:'center',
editoptions:{
size:12,
dataInit:function(el){
$(el).datepicker({dateFormat:'yy-mm-dd',
beforeShow: function(){
$('.ui-datepicker').css({'font-size': 11, 'line-height': 1.2})
}
});
}
},
editrules:{required:true}
},
{name:'male',index:'male', editable:true, formatter:'checkbox',width:100, align:'center',edittype:'checkbox',editoptions:{value:'true:false'}},
{name:'homeTown.nameProvince',editable:true, index:'province', align:'center',edittype:'select',editoptions:{dataUrl:'GetAllProvinceHTML'}}
],
jsonReader : {repeatitems:false},
rowNum: 10,
rowList:[10,20,30],
pager: '#pager',
sortname: 'id',
viewrecords: true,
height: 'auto',
width: 'auto',
sortorder: 'asc',
loadonce: true,
caption:'List Students',
editurl: 'EditStudent'
});
$('#list-student').jqGrid(
'navGrid',
'#pager',
{view:true},
{
reloadAfterSubmit:false,
closeOnEscape:true,
jqModal:true,
afterSubmit:function(response, post_data){
console.log(response.responseText);
},
closeAfterEdit: true
}, // edit options
{reloadAfterSubmit:false,jqModal:true, closeOnEscape:true,bottominfo:'Fields marked with (*) are required', closeAfterAdd: true}, // add options
{reloadAfterSubmit:false,jqModal:true, closeOnEscape:true}, // del options
{closeOnEscape:true}, // search options
{jqModal:true,closeOnEscape:true} // view options
);
in Spring Controller
package controller;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Province;
import model.ProvinceService;
import model.Student;
import model.StudentService;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping(value="PostMes", method = RequestMethod.POST)
public class StudentController {
@RequestMapping(value="Get",method = RequestMethod.GET)
public String abc(){
return "Manage";
}
@RequestMapping(value="GetAllStudent",method = RequestMethod.GET)
public @ResponseBody List<Student> getAllStudent(){
StudentService sts=new StudentService();
List<Student> list= sts.getAllStudents();
return list;
}
@RequestMapping(value="GetAllProvince",method = RequestMethod.GET)
public @ResponseBody List<Province> getAllProvince(){
ProvinceService sts=new ProvinceService();
List<Province> list= sts.getAllProvinces();
return list;
}
@RequestMapping(value = "GetAllProvinceHTML", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
public @ResponseBody String getAllProcinveHTML(HttpServletResponse response){
ProvinceService sts=new ProvinceService();
List<Province> list= sts.getAllProvinces();
String returnString="";
for(Province pro:list){
returnString+="<option id='"+pro.getId()+"'>"+pro.getNameProvince()+"</option>";
}
returnString="<select class='provinceGroup'>" + returnString + "</select>";
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
return returnString;
}
@RequestMapping(value = "EditStudent",method = RequestMethod.POST)
public @ResponseBody List<Student> editStudent(HttpServletRequest request, HttpServletResponse res){
System.out.println(request.getParameter("id"));
System.out.println(request.getParameter("oper"));//what operation we re doing example: "add" , "edit"
System.out.println("Controller recieved");
List<String> returnList=new ArrayList<String>();
List<Student> list=new ArrayList<Student>();
Student st=new Student();
st.setName("Shayne");
list.add(st);
list.add(st);list.add(st);list.add(st);list.add(st);
return list;
}
}
When I edit the line and hit submit => in the requested controller, but after sending the response to the client, I got the message "Uncaught TypeError: Can't read property" 0 "from undefined in jqGrid.min.js"
my include:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/js/jqGrid/grid.locale-en.js"></script>
<script src="${pageContext.request.contextPath}/resources/js/jqGrid/jqGrid.min.js"></script>
+3
source to share