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
JSON object with subobject as datasource for igGrid
posted

I have an igGrid that I want to use a JSON object as the datasource. The object is built from a DB call in an AJAX request from a 'relationship' table and the object associated to it. The relationship table has the parent ID, the type of relationship and the child ID, with all the child details in a child table based on child ID. The data is queried as a Hibernate join between these tables based on the parent ID, so the Java object returned looks like this.

class children {

    int parentID;

    int childID;

    String type;

    Child child;

}

The subsequent JSON object models this list of children as an array of these 'relationships' with the child being a sub-object within each 'row', exactly how it should. My problem is that I can't get the subobject values to appear in my grid. I have it defined like this :

                { headerText: "Type",        key: "type",              dataType: "string" },
                { headerText: "Name",       key: "child.name",    dataType: "string" },

The 'type' field shows up in the grid, but the 'child.name' field does not. I can access the child data fine in javascript exactly how I'd expect, but the grid stays blank.

What am I doing wrong? Thanks in advance...

Parents
  • 23953
    Offline posted

    Hello C J,

    When you want to display complex types you should use column dataType: "object". This will allow you to access the object in the column template and formatter function. The next step is to visualize the name property in formatter function. Here is an example code:

    { headerText: "Name",       key: "child",    dataType: "object", formatter: function (val) {return val.name;} }

    Please note that currently the other grid features are not working with complex object properties in the data source, which means that sorting, filtering, grouping will not work as expected. However this is solved with custom code by using unbound columns.

     

    Hope this helps,
    Martin Pavlov
    Infragistics, Inc.

Reply Children