cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Tree Table: Unable to expand the same node added as a child

nkaur1311
Explorer
0 Kudos

Hello Experts,

I am working on a custom Fiori application. When I am adding rows at the run time in Tree Table, want to keep the same nodes open. But the default behavior of a TreeTable is when something happens with it (either Add a new node/ Delete an existing one), it gets rendered again and all nodes are collapsed.

Default behaviour after adding a row in any node:

add-node.jpg

Expected behavior:

expected.png

I have tried couple of variations wherein I used expand to certain level, but it expands all the nodes at same level

onHierDataRecieved: function (oData) {
			var me = this;
			var level = this.getModel("viewModel").getProperty("/expandToLevel");
			if (level !== "") {
				if (oData.getParameter("data")) {
					if (oData.getParameter("data").results.length > 0) {
						if (oData.getParameter("data").results[0].Parentid === "00000000") {
							var parentLevel = parseInt(formatter.getParentLevel(level));
							this.expandToLevel(parentLevel);
						}
					}
				}
			}
		}

Another try:

I tried to fire the event, toggleOpenState after the success create call but it also seems not to be working fine

this.byId("treeTable").fireToggleOpenState({ rowIndex: me.rowIndex, rowContext: me.rowContext, expanded: true });

If anybody has come across such an issue, kindly revert or suggest if there is any way out to make it possible.

Thanks and Regards,

Navneet K.

Accepted Solutions (0)

Answers (1)

Answers (1)

Fabrice
Active Participant
0 Kudos

Hi,

in our case (SAPUI5 v1.84, OData V2), we used the treeState property of the ODataTreeBinding (API Reference - Demo Kit - SAPUI5 SDK (ondemand.com)) and the function getCurrentTreeState:

var oTreeState = oTreeTable.getBinding("rows").getCurrentTreeState(); 
oTreeTable.getBinding("rows").setTreeState(oTreeState);

But, according to the documentation, there is limitation:
A tree state handle can be given to the ODataTreeBinding when two conditions are met: The binding is running in OperationMode.Client AND the sap.ui.table.TreeTable is used. The feature is only available when using the ODataTreeBindingAdapter, which is automatically applied when using the sap.ui.table.TreeTable. The tree state handle will contain all necessary information to expand the tree to the given state. This feature is not supported in OperationMode.Server and OperationMode.Auto. Please see also the getCurrentTreeState method in class ODataTreeBindingAdapter.

I hope it will help.

Regards

Fabrice

nkaur1311
Explorer
0 Kudos

Hi Fabrice,

Thanks for your response.

I even tried the above approach by upgrdaing the SAPUI5 version and setting OperationMode as Server . But then I didn't get any data. Even oData call is also not triggered.

Regards,

Navneet