on 11-08-2017 11:01 PM
Hello,
I am trying to implement a tree structure with the help of sap.ui.table.TreeTable as shown in Sample. But instead of displaying hierarchy as parent/child nodes, the tree table is displaying every row as parent entry.
We have a flat structure data from a table in json format and without converting them to hierarchical format json, is it possible to display them as parent/child nodes ? Have anybody implemented it ? If yes, can you please share the logic/code information ?
Thanks.
May be this can help you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
You can try like below code.
Because I was having same flat structure to form a treetable.
in your Success method write like
success: function (oData) {
var data = oData.QuestionTree.results;
var flat = {};
for (var i = 0; i < data.length; i++) {
var key = 'id' + data[i].Id;
flat[key] = data[i];
flat[key].__metadata = "";
}
// child container array to each node
for (var i in flat) {
flat[i].children = []; // add children container
}
// populate the child container arrays
for (var i in flat) {
var parentkey = 'id' + flat[i].ParentId;
if (flat[parentkey]) {
flat[parentkey].children.push(flat[i]);
}
}
// find the root nodes (no parent found) and create the hierarchy tree from them
var root = [];
for (var i in flat) {
var parentkey = 'id' + flat[i].ParentId;
if (!flat[parentkey]) {
root.push(flat[i]);
}
}
var oJsonModel = new sap.ui.model.json.JSONModel();
oJsonModel.setData(root);
treeTable.setModel(oJsonModel);
treeTable.bindRows({
path: "/",
parameters: {
arrayNames: ['children'],
numberOfExpandedLevels: length
}
});
}
Thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is the
"HierarchyLevel": 1,
and the
"ParentNodeID": 2,
fields that you need to take care of to ensure that they are set correctly.
HTH,
Nigel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
If you want to display the data in tree format then the you are fetching alsoshould be in the same way.
Please find the example in the below link
https://embed.plnkr.co/pn3BRS4EvjWTMtBfDJia/
Let me know if you have any doubt on this.
Thanks,
Deepak Raj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your inputs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you can't do like this!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
no way
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.