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
Any update on this?
Thanks and regards,Sudipto
Hi, Sudipto.
Sorry for the little bit response. I've directly tried to modified your code but with no success for the moment. It's seems is something small that I'm missing too. That's why I get a working sample and starting from there I will start to modify it for your needs. Meanwhile you can try it also:
var adventureWorksCustomerSales = { "Records": [ { "CustomerID":1, "TerritoryID":1, "AccountNumber":"AW00000001", "ModifiedDate":"\/Date(1097655307263)\/", "GeneratedSales":7136.9199321292353, "CustomerAddresses": { "Records": [ { "AddressID":832, "AddressTypeID":3, "ModifiedDate":"\/Date(996613200000)\/", }] } }]}
$("#grid1").igHierarchicalGrid({ dataSource: adventureWorksCustomerSales, dataSourceType: "json", responseDataKey: "Records", initialDataBindDepth: 1, autoGenerateColumns: false, primaryKey: "CustomerID", columns: [ { key: "CustomerID", headerText: "CustomerID", dataType: "number" }, { key: "TerritoryID", headerText: "TerritoryID", dataType: "number" }, { key: "AccountNumber", headerText: "AccountNumber", dataType: "string" }, { key: "ModifiedDate", headerText: "ModifiedDate", dataType: "date" }, { key: "GeneratedSales", headerText: "GeneratedSales", dataType: "number" } ], autoGenerateLayouts: false, columnLayouts: [ { key: "CustomerAddresses", responseDataKey: "Records", autoGenerateColumns: false, primaryKey: "AddressID", foreignKey: "CustomerID", columns: [ { key: "AddressID", headerText: "AddressID", dataType: "number" }, { key: "AddressTypeID", headerText: "AddressTypeID", dataType: "number" }, { key: "ModifiedDate", headerText: "ModifiedDate", dataType: "date" } ] }]});
So please try this and I will do the same and will keep you posted.
Thanks you for the patience, Sudipto.
Nikolay Alipiev
I found the problem. One of the them was that your primary key column is "id" while when set in the primaryKey and foreignKey it was capitalized "Id". The other thing was that the some of the child columns requested records that was not in the data source, at least that part that you've sent. That's why I left only two and also removed some other unnecessary settings. So I pasted the working sample here as well attached more advanced scenario as HTML file.
var ds = {"page":0, "records":922, "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 }] }]};
$("#AllTasksGrid").igHierarchicalGrid({ initialDataBindDepth: 1, showHeader: true, responseDataKey: 'rows', dataSource: ds, primaryKey: "id", autoGenerateColumns: false, columns: [ { headerText: "Id", key: "id", dataType: "number"}, { 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, columnLayouts: [ { key: "Activities", autoGenerateColumns: false, primaryKey: "ActivityId", foreignKey: "id", columns: [ { key: "ActivityId", headerText: "ID", dataType: "number" }, { key: "Name", headerText: "Name", dataType: "string" } ] }]});
I will wait for your feedback and verification of the case.
Best regards, Nikolay Alipiev
Your proposed solution worked . Thanks a lot for your help.
Regards,