user3708842 user3708842 - 3 months ago 19
Java Question

iggrid fails on null value using servlet as datasource

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?

Answer

Infragistics investigated and found that indeed, this is a bug. They are currently working on a fix.

In the meantime, they provided a workaround by putting the grid definition within an AJAX call and this works.

        //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) {

            }
        });
Comments