Chethan
Chethan

Reputation: 31

How to read all the tiles in the Tile Container SAP UI5

<core:FragmentDefinition xmlns="sap.m"xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
    xmlns:html="http://www.w3.org/1999/xhtml" xmlns:l="sap.ui.layout">
 <Page id="tileInfo" showHeader="false" enableScrolling="true" > 
    <TileContainer    
      id="getTiles"

      tiles="{myModel1>TILECOLLECTION}">    
      <StandardTile 
        icon="{myModel1>icon}"  
        number="{myModel1>number}"  
        info="{myModel1>info}"
        infoState="{myModel1>infostate}" 
        title="{myModel1>title}" 
        numberUnit="{myModel1>numberunit}"
        press="handleTilePress"
        class="myGreen"    
        />   
        </TileContainer>   
       </Page> 
</core:FragmentDefinition>

I want to read each tile in the TileContainer in the view controller. Is it possible ?

Upvotes: 0

Views: 675

Answers (3)

Chethan
Chethan

Reputation: 31

I have added a few more information. If we are not going byId we can use the below code to get the fragment details :

Thanks All. Note : The code does not work in onInit function but works in other functions

var fragmentId = this.getView().createId("myFragment");
var tileContainer = sap.ui.core.Fragment.byId(fragmentId,"getTiles");                               
 var oTiles = tileContainer.getTiles(); 

Upvotes: 0

techippo.com
techippo.com

Reputation: 255

Use nested views instead of fragment. code with nested views

Then you can get the tiles and apply logic below.

var oTileContainer = this.byId("myView--getTiles");
var aTilesLength = oTileContainer.getTiles().length;
for(var i = 0 ;i<aTilesLength;i++){
  if(i%2 == 1){
  oTileContainer.getTiles()[i].addStyleClass("blue");
  }else{
   oTileContainer.getTiles()[i].addStyleClass("green"); 
  }  
}

Upvotes: 0

n01dea
n01dea

Reputation: 1580

in the controller:

...
var oTileContainer = this.byId("getTiles");
var aTiles = oTileContainer.getTiles();
...

in the array aTiles are the tiles of the tiles aggregation of the tile container.

Upvotes: 1

Related Questions