Skip to Content

How to create sap.m.Tree table using ODATA Service (Its in Table Structure)

Jun 30, 2017 at 11:04 AM


avatar image
Former Member

Hello Friends,

Need small help on sap.m.Tree Table. Kindly help me how to create Tree Table as per below screen shot using XML View

ODATA Service is

Kindly help me how to create Tree table using above ODATA Service.?



capture1.png (11.7 kB)
untitled.png (35.9 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member Jun 30, 2017 at 12:05 PM


Try this;

<mvc:View controllerName="test.controller.View1" xmlns:html="" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
	xmlns:viz="sap.viz.ui5.controls" xmlns:layout="sap.ui.layout" xmlns:table="sap.ui.table" xmlns:smartTable="sap.ui.comp.smarttable"
			<Page title="Org. Unit">
					<table:TreeTable id="TreeTable" rows="{path:'nodeModel>/nodeRoot', parameters: {arrayNames:['children']}}" enableSelectAll="false"
								<Label text="Type"/>
									<Text text="{nodeModel>id}"/>
							<table:Column width="20rem">
								<Label text="Orgeh"/>
									<Text text="{nodeModel>text}"/>
							<table:Column width="4rem">
								<Label text="Type"/>
									<Text text="{nodeModel>type}"/>
							<table:Column >
								<Label text="Tag"/>
									<Text text="{nodeModel>tag}"/>
							<table:Column >
								<Label text="Betrag"/>
									<Text text="{nodeModel>betrag}"/>

					<!--					<Tree items="{path:'nodeModel>/nodeRoot', parameters: {arrayNames:['children']}}">
						<StandardTreeItem title="{nodeModel>text}"/>


		onInit: function() {
			var flatData = this.readFile();
			var deepData = this.transformTreeData(flatData);


		readFile: function() {

			var flatData = null;
			//load the data from the JSON file
			//NB same format as gateway service could be
			var inModel = new sap.ui.model.json.JSONModel();
			inModel.loadData("/sap/opu/odata/SAP/Z_ECA_TEST02_SRV/SubOrgsSet?$format=json", "", false);

			var data = inModel.getData();
			if (data) {
				flatData = data.d.results;

			return flatData;

		transformTreeData: function(nodesIn) {

			var nodes = []; //'deep' object structure
			var nodeMap = {}; //'map', each node is an attribute

			if (nodesIn) {

				var nodeOut;
				var parentOrgeh;

				for (var i = 0; i < nodesIn.length; i++) {
					var nodeIn = nodesIn[i];
					nodeOut = {
						id: nodeIn.Orgeh,
						text: nodeIn.Stext,
						type: nodeIn.Otype,
						tag: nodeIn.Tag,
						betrag: nodeIn.Betrag,
						children: []

					parentOrgeh = nodeIn.ParentOrgeh;

					if (parentOrgeh && parentOrgeh.length > 0) {
						//we have a parent, add the node there
						//NB because object references are used, changing the node
						//in the nodeMap changes it in the nodes array too
						//(we rely on parents always appearing before their children)
						var parent = nodeMap[nodeIn.ParentOrgeh];

						if (parent) {
					} else {
						//there is no parent, must be top level

					//add the node to the node map, which is a simple 1-level list of all nodes

					nodeMap[] = nodeOut;



			return nodes;

		setModelData: function(nodes) {
			//store the nodes in the JSON model, so the view can access them
			var nodesModel = new sap.ui.model.json.JSONModel();
				nodeRoot: {
					children: nodes
			this.getView().setModel(nodesModel, "nodeModel");

10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jul 06, 2017 at 06:36 AM


Thanks for help.

10 |10000 characters needed characters left characters exceeded