I'm trying to use a formatter to change the color of a number in a table. However, it doesn't seem like the formatter is being called:
index.html
!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="UTF-8">
<script id="sap-ui-bootstrap"
src="/sap/ui5/1/resources/sap-ui-core.js"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-resourceroots='{"ui5": "./"}'>
</script>
<script>
// now create a new, reusable component called ui5 (like our namespace)
new sap.ui.core.ComponentContainer({
name: "ui5"
// insert all the code generated by UI5 into the element with ID 'content'
}).placeAt("content");
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
Tables.view.xml
<mvc:View
controllerName="ui5.view.Tables"
xmlns:l="sap.ui.layout"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Page
showNavButton = "true"
navButtonPress = "handleNavButtonPress"
title="Products" >
<Table id="idProductsTable"
inset="false"
items="{/ProductsCollection}">
<columns>
<Column>
<Text text="Qty" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<ObjectNumber
number="{INVENTORY}"
state="{ path: 'INVENTORY', formatter: 'ui5.util.Formatter.inventoryQty' }" />
</cells>
</ColumnListItem>
</items>
</Table>
</Page>
</mvc:View>
Tables.controller.js
jQuery.sap.require("ui5.util.Formatter");
sap.ui.controller("ui5.view.Tables", {
handleNavButtonPress: function(evt){
this.nav.back("Master");
},
onInit: function () {
var oModel = new sap.ui.model.json.JSONModel("model/gbi.json");
this.getView().setModel(oModel);
}
});
gbi.json
{
"ProductsCollection" : [
{
"INVENTORY" : 1250
},
{
"INVENTORY" : 1000
}
]}
Formatter.js (located in the util folder
jQuery.sap.declare("ui5.util.Formatter");
ui5.util.Formatter = {
inventoryQty : function (fValue) {
fValue = parseInt(fValue);
try {
if (fValue < 0) {
return "None";
} else if (fValue < 100) {
return "Warning";
} else {
return "Success";
}
} catch (err) {
return "None";
}
}
};
It's loading the Formatter.js file but doesn't invoke it. Any help will be greatly appreciated.
Thanks,
Ross