<t:TreeTable id="treeTable" visibleRowCount="5" enableColumnReordering="true" toggleOpenState = "toggleOpenState">
<t:columns>
<t:Column label="Description">
<t:template>
<Text text="{WBSParent}"/>
</t:template>
</t:Column>
<t:Column label="WBSElement">
<t:template>
<Text text="{WBSElement}"/>
</t:template>
</t:Column>
</t:columns>
</t:TreeTable>
var serviceUrl1 = "/sap/opu/odata/sap/z_data_srv/";
var oModel1 = new sap.ui.model.odata.ODataModel(serviceUrl1, true);
var oJSModel1 = new sap.ui.model.json.JSONModel();
var oTreeTable = this.getView().byId("treeTable").setModel(oJSModel1);
/ *note that this oData service URL has NavDocs as expand node, treetable has capability to find this node from you service metadata and map it in tree structure, that is the reason below i can simply directly use bindRows to treetable. */
oModel1.read(
"/WBSDataSet?$filter=WBSElement eq " + "'" + WBSElement1 + "'" + "&$expand=NavDocs",
null, [],
true,
function(oData, oResponse) {
var data = oData.results;
oJSModel1.setData(data);
oTreeTable.bindRows({
path: "/"
});
},
function(oError) {
console.log(oError);
}
);
oTreeTable.bindRows({
path: "/",
parameters:{
arrayNames:['NavDocs']}
});
var arrHeader = oData.results;
var flat = {};
for (var i in arrHeader) {
var key = 'id' + arrHeader[i].WBSElement;
flat[key] = arrHeader[i];
flat[key].__metadata = "";
}
//------------------------
// add child container array to each node
for (var j in flat) {
flat[j].children = [];
}
// populate the child container arrays
for (var k in flat) {
var parentkey = 'id' + flat[k].WBSParent;
var childkey = 'id' + flat[k].WBSElement;
if (flat[parentkey] === flat[childkey]) {
k++;
} else {
flat[parentkey].children.push(flat[k]);
}
}
// find the root nodes (no parent found) and create the hierarchy tree from them
var root = [];
for (var l in flat) {
var parentkey1 = 'id' + flat[l].WBSParent;
var childkey1 = 'id' + flat[l].WBSElement;
if (flat[parentkey1] === flat[childkey1]) {
root.push(flat[l]);
}
}
var data = {
root: root
};
oJSModel1.setData(data);
oTreeTable.bindRows({
path: "/root",
parameters: {
arrayNames: ['children']
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 |