Search code examples
sapui5

SAPUI5 table in list


I have a view:

<List
        items="{data>/Stages}">
           <CustomListItem>
            <Panel>
                <headerToolbar>
                     <Toolbar>
                         <content>
                           <Button
                              visible="{= ${data>/Stages/length} > 1}" />
                         </content>
                     </Toolbar>
                 </headerToolbar>
                 <content>
                 <Table
                   growing="true" 
                   growingScrollToLoad="false"
                   items="{
                       path: 'data>FieldWorks',
                       templateShareable: true
                   }"
                   class="blueTable originTable techTable">
                   <columns>
                     <Column
                       visible="true"
                       vAlign="Middle" 
                       width="15px" />
                   </columns>
                   <items>
                     <ColumnListItem>
                         <cells>
                          <core:Icon
                              visible="{ ???}"
                              src="sap-icon://customfont/moving"
                              size="2.1rem"
                              color="#14c6c9" />
                         </cells>
                     </ColumnListItem>
                  </items>
               </Table>
            </content>
        </Panel>
    </CustomListItem>
</List>

I have a model (example):

data: {
   Stages: [{
       FieldWorks: [{}, ....]
    }, .....]
}

I hide my button (in my toolBar) by expression binding as you can see. What is the best way to hide my Icon (in CustomListItem) by condition FieldWorks.length > 1


Solution

  • If you are using a JSON Model just add boolean property to your JSONModel to the FieldWorks entity and bind the visible property to it. Then one time you have to set it when data is loaded or created and that's it.