Skip to Content
0

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

Dec 11, 2017 at 08:41 AM

31

avatar image

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>


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
saurabh vakil Dec 11, 2017 at 09:39 AM
1

Change the below line

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

as

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

done..still formatter not working

0

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.

0