cancel
Showing results for 
Search instead for 
Did you mean: 

Usage example for ODataTreeBinding parameter treeSate

sergiu_popa
Participant
0 Kudos

Hello experts,

I am currently trying to find a solution for keeping the state (expanded / collapsed) of nodes from a sap.ui.table.TreeTable after saving changes done to TreeTable entries to the BE.

Scenario: I have a TreeTable binded to an OData v2 webservice with operationMode='Client' on SAPUI5 v 1.52.13. There are different properties of the TreeTable entries that can be changed by users (e.g.: a user can set a new price for an entry in the table).

The issue: After saving the changes done to the TreeTable entries, the table is triggering a request to the BE to reload the data. At this point, the state of the TreeTable is reset. The nodes that were expanded or collapsed are restored to their initial state.

Looking into the corresponding SAPUI5 documentation I noticed there is a binding parameter called treeState. To me, this seems to be a possible solution for not losing the expanded / collapsed state of the nodes after saving changes.
The problem that I have is that the documentation is vague and I can't find any examples of how this parameter could be used.

The following are unclear to me:

  • how do I get access to the ODataTreeBindingAdapter; I need this so I can call getCurrentTreeState for "snapshotting" the TreeTable state before save
  • what should actually be passed for treeState? The documentation mentions a boolean variable, but if I look into the TreeBindingAdapter, it seems that treeState should actually be an object with some specific functions.
  • Is there any way to create a TreeState object besides using getCurrentTreeState from ODataTreeBindingAdapter?

Thank you and have a good day!
SePo

Accepted Solutions (1)

Accepted Solutions (1)

Fabrice
Active Participant

Hi,

Before the refresh, we do that :

this._oTreeState = this._oTable.getBinding("rows").getCurrentTreeState();
this._oTable.getBinding("rows").setTreeState(this._oTreeState);
this.getModel().refresh();

Regards

Fabrice

sergiu_popa
Participant
0 Kudos

Hi Fabrice,

Thank you for you quick answer!

What version of SAPUI5 are you using? I'm asking because I tried the same thing but "getCurrentTreeState" is not found on the binding object.

Also, are you providing a treeState via binding parameters when you initialize the TreeTable binding?

Thank you!
SePo

Fabrice
Active Participant

Hi,

We use version 1.52

the binding is like that :

this._otable.bindRows({
path :  <our_path>,
parameters : {
  countMode: "Inline",
  operationMode:sap.ui.model.odata.OperationMode.Client,
  numberOfExpandedLevels: iNumberOfExpandedLevels,
  treeAnnotationProperties : {
    hierarchyLevelFor : iHierarchyLevelFor ,
    hierarchyNodeFor : sHierarchyNodeFor ,
    hierarchyParentNodeFor : sHierarchyParentNodeFor ,
    hierarchyDrillStateFor : sHierarchyDrillStateFor 
  }
}
});

Regards

Fabrice

sergiu_popa
Participant
0 Kudos

Hmm... this gets even stranger :-).

I too am using 1.52 and the binding is similar (except treeAnnotationProperties; I'm using the annotations on the metadata level).

Thanks for your help Fabrice... I guess I have to look deeper into the SAPUI5 code and see why the ODataTreeBindingAdapter doesn't add these methods (getCurrentTreeState and setTreeState) to the ODataTreeBinding of my table.

Answers (1)

Answers (1)

sergiu_popa
Participant
0 Kudos

Hi Fabrice,

I figure out what happens... the TreeTable that I expected to have this method is inside a SmartTable. It seems that the bindings of TreeTables inside SmartTables don't get this method as long as enableAutoBinding = true.

Thanks!

Have a good day!
SePo

Fabrice
Active Participant
0 Kudos

Hi,

sorry that i cannot help you more.

Have also a good day!

Fabrice