I have an igGrid that displays fields from a database table which has some entries that are NULL.
$.ig.loader(function () {
$.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?
Hello,
Thank you for contacting us and for the provided detailed explanation.
I have managed to reproduce the issue based on your explanation and I have asked our engineering staff to examine this further. To ensure that it will receive attention, I have logged this behavior in our internal tracking system with a Development ID of 178135. A support case is created on your behalf with number CAS-142218-J4P0V3, so that you can be notified when the bug is fixed. You can find your active cases under Account - Support Activity in our website. Select your ticket and go to Development Issues tab to view the status of related bugs.
While we wait this issue to be fixed I can suggest you a temporary workaround. As you have noticed if you pass the data locally the exception will not be thrown, so you can use AJAX request to your servlet in order to get the data and on success to pass it to the igGrid. Or you can serialize your object in order to have "type" property with "null" value.
Have a look at the code snippet below for more information.
Code snippet:
<script> $(function () { var data = [{ "id": "ID1", "name": "Name1", "type": "regular" }, { "id": "ID2", "name": "Name2" }]; //grid1 will initialize correctly $("#grid1").igGrid({ autoGenerateColumns: false, dataSource: data, columns: [ { headerText: "ID", key: "id", dataType: "string" }, { headerText: "Name", key: "name", dataType: "string" }, { headerText: "Type", key: "type", dataType: "string" } ], }); //grid2 will initialize correctly $.ajax({ type: "POST", url: '@Url.Action("GetJsonString", "Home")', contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { var result = response; debugger; $("#grid2").igGrid({ autoGenerateColumns: false, dataSource: result, columns: [ { headerText: "ID", key: "id", dataType: "string" }, { headerText: "Name", key: "name", dataType: "string" }, { headerText: "Type", key: "type", dataType: "string" } ], }); }, error: function (response) { } }); //grid3 will not $("#grid3").igGrid({ autoGenerateColumns: false, dataSource: '@Url.Action("GetJsonString", "Home")', dataSourceType: "json", columns: [ { headerText: "ID", key: "id", dataType: "string" }, { headerText: "Name", key: "name", dataType: "string" }, { headerText: "Type", key: "type", dataType: "string" } ], }); }); script>
I thought I replied to this answer as well as marking it 'correct.' The code snippet using AJAX did indeed work and I can load the JSON data with NULL values. I would like to remove this extra code once this is fixed and will monitor the ticket that you created for this issue.
Thanks.
I am glad to hear that this temporary approach is working on your side also. Thank you for your collaboration and for reporting this issue.
Once it is fixed you will be automatically notified.
Thank you for using our controls.