Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
960
iggrid fails on null value using servlet as datasource
posted

I have an igGrid that displays fields from a database table which has some entries that are NULL.

 $.ig.loader(function () { 
 $("#igGrid").igGrid({ 
 autoGenerateColumns: false, 
 dataSource: "/myapp/SrvUser?parm=all", 
 columns: [ 
 { headerText: "ID", key: "id", dataType: "string" }, 
 { headerText: "Name", key: "name", dataType: "string" }, 
 { headerText: "Type", key: "type", dataType: "string" } 
 ], 
 features: [{ blah ... }] });

And the servlet returns data like this :

 userList = (List<BeanUser>) DButil.getUserList(parm); 
 String json = gson.toJson(userList); 
 response.setContentType("application/json"); 
 response.getWriter().write(json);

Which fails if ANY column is NULL with this error :

Error: The remote request to fetch data has failed: (parsererror) There was an error parsing the JSON data and applying the defined data schema: 
The input data doesn't match the schema, the following field couldn't be mapped: type

The tricky part is that in Eclipse Debug, I set a breakpoint, captured the JSON data in the servlet just before its sent and if I use THIS exact data in my grid definition it works!

var data = [{"id":"ID1","name":"Name1","type":"regular"}, 
 {"id":"ID2","name":"Name2"} ]; 
$.ig.loader(function () { . . . dataSource: data,

So its not the grid definition and I have other igGrids that contain NULL values (which appear correctly as blank in the grid), but those grids do NOT use a servlet as the dataSource. They use this :

dataSource: $.parseJSON('<%=request.getAttribute("jsonData")%>'),

Do I have to change something in my servlet? Or grid definition? Is there another way of defining a dataSource to get its data from a servlet?