sapui5sap-fiori

Smart table column with action attached


I am using a Smart Table in my SAPUI5 app with no custom columns, so all the columns are coming from OData. One column should be like a link, so if user presses the data in the column, it should open up a dialog or fragment to navigate further or execute an action. So two questions, I have not been able to figure out:

  1. How to format a column which is not a custom column, as a link?
  2. Have an action on the column (like CellClick or similar)?

Solution

    1. You can in the XML view redefine smarttable columns using CustomData, here a SAP blog
    2. You can use a sap.m.Link or a sap.m.Button inside the cell or by adding an event listener when the row is clicked like attachItemPress

    <smartTable:SmartTable>    
      <Table>
       <columns>
          <Column>
            <customData>
              <core:CustomData key="p13nData" value='\{"columnKey": "yourKey", "leadingProperty": "yourLeadingProperty", "columnIndex": theIndex}'/>
            </customData>
            <Text text="{i18n>YourPropertyName}"></Text>
          </Column>
        </columns>
        <items>
          <ColumnListItem>
            <Link text="{LinkText}" href="YourLink"/>
          </ColumnListItem>
        </items>
      </Table>
    </smartTable:SmartTable>