Hi,
I am trying to bind json data to my Hieararchical grid.Following is the initialization:
$("#AllTasksGrid").igHierarchicalGrid({ initialDataBindDepth: 1, showHeader: true, responseDataKey: 'rows', dataSource: '@Url.Action("GetAllTasksAndActivities", "Home")', primaryKey: "Id", autoGenerateColumns: false, columns: [ { headerText: "Id", key: "id", dataType: "string", hidden: true }, { headerText: "Code", key: "businessCode", dataType: "string"}, { headerText: "Type", key: "taskType", dataType: "string"}, { headerText: "Task/Activity Name", key: "taskName", dataType: "string"}, { headerText: "Country", key: "countryList", dataType: "string" }, { headerText: "Status", key: "Status", dataType: "string" }, { headerText: "Start Date", key: "StartDate", dataType: "string" }, { headerText: "Deadline", key: "Deadline", dataType: "string" } ], autoGenerateLayouts: false, defaultChildrenDataProperty: "Activities", columnLayouts: [ { key: "Activities", responseDataKey: "Activities", childrenDataProperty: "Activities", autoGenerateColumns: false, primaryKey: "ActivityId", foreignKey: "Id", columns: [ { key: "ActivityId", headerText: "ID", dataType: "string" }, { key: "Name", headerText: "Name", dataType: "string" }, { key: "Status", headerText: "Status", dataType: "string" }, { key: "StartDate", headerText: "Start Date", dataType: "string" }, { key: "Deadline", headerText: "Deadline", dataType: "string" } ] } ], features: [ { name: "Paging", type: "remote", pageSize: 10, recordCountKey: 'records' }, { name: "Sorting", type: "remote" }, { name: "Tooltips", columnSettings: [ { columnKey: "taskname", allowTooltips: true } ], visibility: "overflow", showDelay: 100, hideDelay: 100 }
] });
--------------------------------------------------------------------------------------------------------------------------------
Following is the json data i am receiving
{"page":0,
"records":896,
"rows":[{"id":359,"businessCode":"12121212","taskType":"Task","taskName":"Task","countryList":"AAA","Status":"P","StartDate":"2012-10-23","Deadline":"","Activities":[{"ParentTaskId":0,"ActivityId":480,"Name":"Update Acitivy 2 new 1 2 3","IsNameEnabled":false,"BusinessCode":null,"AssignedTo":null,"IsAssignedToEnabled":false,"AssignedToName":null,
........
However when the grid renders it only renders the parent rows but child values are empty. Is there something wrong with the initialization?
Hi, Sudipto Roy.
Thank you for using our product.
You may try remove the responseDataKey of the child column layout. This is bacause in the data source you have "Activities": [{...}]. If you don't want to remove the responseDataKey and preserve the same configuration, then you need to modify the data source to so that the JSON for the child layout to be - "Activities": {"Activities": [{...}]}.
Best regards,
Nikolay Alipeiv
Hi Nikolay,
Thanks for the prompt response. I tried both your suggestions but the grid still doesn't render child elements.It shows only the column headers.For the second approach I modified the data source so that the json returned is:
"records":922,
"rows":[{"id":359,"businessCode":"12121212","taskType":"Task","taskName":"Test","country":"DF","Status":"P","StartDate":"2012-10-23","Deadline":"",
"Activities":{"Activities":[{"ParentTaskId":0,"ProgressStatus":null,"IsProgressStatusEnabled":false , ............
Is there something still missing or misconfigured?
Thanks and regards,
Sudipto
Hi, Bob.
For any other issues don't hesitate to ask us and create a forum post.
Nikolay
Thanks for responding. I think it's best for me to just understand how to work with the current implementation of the igHier Grid.
In my case, I need to make several service calls to get the data I need. And since I'm receiving various collections from the service calls, I need to use server-side C# code to reorganize the data in a hierarchical manner which is fit for your grid.
so as long as I know that I need to massage my Json data a bit before rendering the Hier Grid, then that's fine.
thanks again.
Bob
This cannot be achieved with external data source - the data source should be with hierarchical structure. The igHierarchicalDataSource is specially created for handling hierarchical data and it also cannot work with multiple data sources. If you want you can give me more details of the scenario you want to achieve and we will come with some solution. Just FYI, we have a igMashupDataSource, which can combine different type of data source into a one, but it's working only for flat ones.
Nikolay Alipiev
Hello Nikolay,
I regards to your example JSON data here, is it possible to retrieve the "CustomerAddresses" JSON data in a completely different data set and have the igHierarchGrid discover the relationship via the primary and For keys ?
Or does it indeed have to be in this format where the Parent/Child data Json data is already in place as in your example below ?
var adventureWorksCustomerSales = { "Records": [ { "CustomerID":1, "TerritoryID":1, "AccountNumber":"AW00000001", "ModifiedDate":"\/Date(1097655307263)\/", "GeneratedSales":7136.9199321292353, "CustomerAddresses": { "Records": [ { "AddressID":832, "AddressTypeID":3, "ModifiedDate":"\/Date(996613200000)\/", }] } }]}
ex/ In other words could I have these two datasets as follows ?
"Records": [ { "CustomerID":1, "TerritoryID":1, "AccountNumber":"AW00000001", "ModifiedDate":"\/Date(1097655307263)\/", "GeneratedSales":7136.9199321292353 }]}
"CustomerAddresses": { "Records": [ {
"CustomerID":1, "AddressID":832, "AddressTypeID":3, "ModifiedDate":"\/Date(996613200000)\/", }] }
Your proposed solution worked . Thanks a lot for your help.
Regards,