Hi There,
I'm using the Tree Grid to display some recursive hierarchical data, but the Selection API doesn't appear to work when selecting the nested rows.
Can you please give me an example of this working? I actually need the DATA of the selected row.
The documentation doesn't go in to this as its inherited from the igGrid and this doesn't deal with hierarchical data.
My grid code:
$("#treeGrid").igTreeGrid({ width: "100%", height: w, dataSource: data, dataSourceType: 'json', autoGenerateColumns: false, columns: [ { key: "name", headerText: "Name", dataType: "string", width: 550, template: "<span> <img src='${iconPath}' /> ${name} </span>" }, { key: "weight", headerText: "Weight", dataType: "string" },{ key: "ccy", headerText: "CCY", dataType: "string" }, { key: "type", headerText: "Type", dataType: "string" },
//Leave this in... it doesn't render the icon in the template if the path isn't bound to something { key: "iconPath", headerText: "Icon", dataType: "string", hidden: true }, { key: "id", headerText: "Id", dataType: "string", hidden: true }, ], childDataKey: 'constituents', renderExpandColumn: true, initialExpandDepth: 0, features: [ { name: "Selection", multipleSelection: false, activation: true, rowSelectionChanged: function (evt, ui) {
//nothing in this method, or any inspection of the objects reveals any way to get the data of the selected nested row
var grid = $('#treeGrid'); var row = $('#treeGrid').igTreeGrid('selectedRow'); var activeRow = $('#treeGrid').igTreeGrid('activeRow'); var data = $('#treeGrid').data('igTreeGrid').dataSource.dataView(); var dataRow1 = ui.row.element.data; var dataRow = ui.row.element.data();
var selectedData = data[row.index];
} }, ] });
Many thanks,
Matt
Hello Matt,
Thank you for posting into our community!
Actually the ui.row parameter is returning the information you require.
Here's a fiddle to demonstrate this, please let me know if it helps.
Thanks, turns out I hadn't set the primary key, hence the reason the ID's didn't correspond.
Its still not quite perfect though, as I still have to recursively loop through my data set each time to find the data item with the selected ID.
Is there a cleaner way to call the Grid for the selected Data?
If I have a data set of a couple of thousand rows with multiple levels of nesting, just selecting a nested row could be very expensive and lock the UI.
Regards,