Search code examples
odatasapui5

How to change text for icon in Smart Table SAPUI5


I'm trying to convert Status values 0,1 in Smart Table to icons with formatter. So far I created Custom column and populated it with OData and inserted into Smart Table.

Here is my code in XML view for Custom column:

</Column>
</columns>
<items>
<ColumnListItem>
 <cells>
  <ObjectStatus 
 text="{Status}" state="{path: 'Status', formatter: '.status'}" />
 </cells>
</ColumnListItem>
</items>
</Table>

And this is my controller:

status : function(Status){
    if (Status === "0" ){return new sap.ui.core.IconPool.getIconURI("sap-icon://accept");
    }
    else {return new sap.ui.core.IconPool.getIconURI("sap-icon://decline");
    }
   },

And I got this error in chrome debugger Error screenshot


Solution

  • Icons are supposed to be passed to the ObjectStatus control using property icon, not state. The state property should contain a string/text value which will be used as a textual label.

    The formatter could also be much simpler. Instead of passing URI's, you can pass the icon urls as strings:

    status: function(Status) {
        if (Status === "0") {
            return "sap-icon://accept";
        } else {
            return "sap-icon://decline";
        }
    }