Skip to Content

How to apply formatter to text in which is in table (Xml view)

controller.js

sap.ui.define([
	"sap/ui/core/mvc/Controller",
	"PPNBProjectPlanningNonBillable/model/formatter"
], function(Controller,formatter) {
	"use strict";


	return Controller.extend("PPNBProjectPlanningNonBillable.controller.Detail", {
		
		formatter: formatter,
rest of the code.........
}

formatter.js

sap.ui.define([], function() {
	"use strict";


	return {
		


	
		statusColor: function(sValue) {
			if (sValue === "1") {
			 
			this.getView().byId("table1").addStyleClass(".yellow"); 
			
			} else if (sValue === "2") {
				//return "blue";
			} else if (sValue === "3") {
				//return "yellow";
			} else {
				//return "white";
			}
				return sValue;
		}


	};


});

View.Xml

<Table showNoData="false" id="table1">
<columns>
<Column  width="8%">
<Text  text="Level"/>
</Column>
rest of the code.........

</columns>
</Table>
<ScrollContainer height="425px" vertical="true" focusable="true">
<Table    growing="true" growingThreshold="10" id="idProductsTable" inset="false" items="{ path: 'oDataModel>/Table' }">

<items>
<ColumnListItem>
<cells>
<Text id="text1" text="{path:'oDataModel>Stufe' , formatter:'formatter.statusColor'}"/>

rest of the code.........

</cells>
</ColumnListItem>
</items>
</Table>


Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Dec 11, 2017 at 09:39 AM

    Change the below line

    <Textid="text1" text="{path:'oDataModel>Stufe' , formatter:'formatter.statusColor'}"/>

    as

    <Textid="text1" text="{path:'oDataModel>Stufe' , formatter:'.formatter.statusColor'}"/>
    
    Add comment
    10|10000 characters needed characters exceeded

    • From what I can see, the formatter function returns the color indicating the valueState of the control which displays as red/green/orange etc. sap.m.Text does not have any valueState property associated with it.

      Instead of using sap.m.Text within your table's items aggregation try using ObjectListItem as given here - SAPUI5 SDK - Step 23: Custom Formatters and show your text using an ObjectStatus where you also mention the formatter.