Skip to Content

SAPUI5 TreeTable's getRows method returns empty array on the first call

Sep 15, 2017 at 12:40 PM


avatar image
Former Member

I am trying to build an SAPUI5 application using TreeTable and I'm facing some problems to use its methods. In my app, I have a button which triggers this method.

onChangeViewContext: function(oEvent) {


var aViewContext = oContext.oModel.getProperty(sPath + "/ViewContext");
var aDataModel = oContext.oModel.getProperty("/ApplicationCollection/" + sAppId + "/DataModel"); 
var oStructure = this._createParentChildStructure(aDataModel);
var oTreeModel = this.getView().getModel("treeModel"); 
this._oViewDetailLine = oSource.getParent().getParent().getParent(); 
this._setSelectedItems(aViewContext, oTree); 

What I'm trying to do here is only bind the rows with my treeModel, get tree table object and send it to my _setSelectedItems method which below.

_setSelectedItems: function(aViewContext, oTree) {

var sElementName; 
var aSelectedIndices = []; 
var aElements = []; 
var aRows = oTree.getRows(); 
aRows.forEach(function(row) { 
   if (row._oNodeState !== undefined) { 

I need to get rows array here because I will use it for setting selected items of tree table. The problem is when "onChangeViewContext" triggered, oTable.getRows() returns an empty array. But when I click cancel button (which just hides my tree table, nothing more) and then trigger "onChangeViewContext" function again, I can get the rows array completely. Even on the first call when I try to get table's model, I can get the treeModel and its data correctly. I've tried to refresh bindings, aggregations etc. But no luck. By the way, I'm using row binding in my xml view like this :

<t:TreeTable id="idSelectElementsTree" rows="{path: 'treeModel>/'}" selectionMode="MultiToggle" enableSelectAll="false" rowSelectionChange="onSelectElement">

I'm really drowning here so any any help would be appreciated.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers