Hi,
I am creating a treegrid, and then afterwards populating it with flat data that has primaryKey-foreignKey relationship.
Initially I was using JSONDataSource, but that caused the data to be flat.
Not I am using TreeHierarchicalDataSource, but I get an error when I try to set the dataSource on the treegrid. I tried creating a schema, but still get the same error.
Can you please advise?
Thank you!
The Tree Grid and the ajax call:
$("#tree-grid").igTreeGrid({ updateUrl: saveDataRowUrl, //dataSourceType: "json", autoGenerateColumns: false, autofitLastColumn: false, primaryKey: "PrimaryKey", foreignKey: "ParentId", foreignKeyRootValue: "0_0", initialExpandDepth: 0, enableHoverStyles: true, autoCommit: false, fixedHeaders: true, renderExpansionIndicatorColumn: true, columns: gridOptions.getColumns(), features: [ { name: "Filtering", type: "local", mode: "simple" }, { name: "Sorting", type: "local", mode: "single", columnSettings: gridOptions.getSortingColumnSettings() }, { name: "Updating", enableAddRow: false, enableDeleteRow: false, enableAddChild: false, editMode: "cell", horizontalMoveOnEnter: true, columnSettings: gridOptions.getUpdatingColumnSettings() }, { name: "RowSelectors", enableRowNumbering: false }, { name: "Selection", mode: "cell", multipleSelection: false, activation: true }, ], rendered: function (evt, ui) { otcQuotePageOptions.getQuoteDataRows("#tree-grid", guid); } }); function getQuoteDataRows(selector, guid) { $.ajax({ url: "Home/GetDataRows", cache: false, type: "post", data: { "guid": guid } }) .done(function (jsonData) { var schema = getDataRowSchema(); var datasource = new $.ig.TreeHierarchicalDataSource({ type: "json", data: jsonData, schema: schema, primaryKey: "PrimaryKey", treeDS: { foreignKey: "ParentId", initialExpandDepth: 0 } }); $(selector).igTreeGrid("option", "dataSource", datasource); $(selector).igTreeGrid("dataBind"); }) .fail(function (xhr, ajaxOptions, errorThrown) { console.error("Response: " + xhr.responseText); console.error("Status: " + xhr.status); console.error(errorThrown); }); }
The error message:
infragistics.core.js:264 Uncaught Error: There was an error parsing the JSON data and applying the defined data schema: Cannot read property 'Metadata' of null
I've also tried the following.
var datasource = new $.ig.TreeHierarchicalDataSource(); $.each(jsonData, function (index, value) { datasource.insertRow(value.PrimaryKey, value, index, true, value.ParentId); }); datasource.dataBind(); datasource.commit(); datasource.allTransactions().clear(); try { $(selector).igTreeGrid("option", "dataSource", datasource); $(selector).igTreeGrid("dataBind"); } catch (e) { console.error(e); }
On debugging, the debugger stops stepping through code at this line:
$(selector).igTreeGrid("option", "dataSource", datasource);
Hello C R,
I believe that you don't use the right selector in your case. You should use $("#tree-grid") as selector when you're setting the datasource. Please let me know if you're still encountering the same issue after making the correction.
Regards,Tsanna