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...
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.
Thank you! I used your example and got the correct field to display.
I would like sorting to work on these complex columns and I see how to set the column 'unbound'. But can you provide an example of the 'custom code' you mentioned to allow sorting on these columns?
Thanks again.
Is it possible to specify all of the iggrid options of the comlex object sorting sample declaratively in the view? I'm especially interested in how to specify the unbound column with the "formula" option declaratively.
Hello CJ,
Please let us know if you have any further questions regarding this matter.
I'm attaching a sample. Click the "child" column header to sort the complex unbound column. Note that I've used a separate hidden object column in order to get access to the "name" property. This is because igGrid builds a data schema from the columns configuration and by default it will not include the "child" property in the resulting data and you'll not be able to access it in the formula function.
Hope this helps,Martin PavlovInfragistics, Inc.