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>
Hi, im receiving the same error in the console "The input data doesn't match the schema, the following field couldn't be mapped: ANY_PROPERTY"
where ANY_PROPERTY = the first column/property in definition of columns (not null) i.e. IdTransaccion, IdTipo, ..., etc
json string from webmethod:{\"IdTransaccion\":14172,\"IdTipo\":2,\"IdFondo\":2813,\"IdCliente\":68,\"IdSubCliente\":289,\"IdEstadoTransaccion\":1,\"IdManager\":0,\"NombreCliente\":\"Bancard\",\"NombreFondo\":\"Schroders ASIA PACIFIC PROPERTY SECURITIES (C)\",\"NombreSubcuenta\":\"Mediterraneo Fondo de Inversion Privado\",\"NombreManager\":null,\"NombreMoneda\":\"Shares\",\"TieneFotoOrden\":false,\"TieneFotoConf\":false,\"AgregarComoNuevo\":false,\"FechaIngreso\":\"2014-06-27T00:00:00\",\"FechaModificacion\":\"2014-06-27T00:00:00\",\"FechaTrade\":\"2014-06-30T00:00:00\",\"FechaNAV\":\"2014-06-30T00:00:00\",\"FechaSettlement\":\"2014-07-03T00:00:00\",\"FechaValorizacion\":\"0001-01-01T00:00:00\",\"ISIN\":\"LU0269906375\",\"Ticker\":\"SCAPPCA LX\",\"MontoOriginal\":-111.0,\"UnidadOriginal\":\"14\",\"NumeroCuentaCliente\":\"MEDS100093\",\"MontoFinalShares\":-1.0,\"MontoFinalNAV\":4.0,\"MontoFinalMonedaFondo\":-4.0,\"MontoFinalUnidad\":\"14\",\"MontoFinalTipoCambio\":1.0,\"MontoFinalUSD\":-4.0,\"Confirmaciones\":\"14606\",\"Comentarios\":null,\"Transfer\":\"0\"}
Hello Mario,
This is happening because the JSON is not formed well, the brackets [ and ] are missing. For example, this is the method that returns the test JSON from my sample (you can find it attached to this reply).
public string GetJsonString()
{ string data = "[{ \"id\": \"ID1\", \"name\": \"Name1\", \"type\": \"regular\" }, { \"id\": \"ID2\", \"name\": \"Name2\" }]"; return data; }