<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="UTF-8">
    <title>Formatting Test</title>
    <script id="sap-ui-bootstrap" type="text/javascript" src="https://openui5.hana.ondemand.com/1.32.10/resources/sap-ui-core.js" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-xx-bindingSyntax="complex" >
    </script>
    <!-- XML-based view definition -->
    <script id="demoView" type="sapui5/xmlview">
        <mvc:View height="100%" width="100%" controllerName="local.controller" xmlns:t="sap.ui.table" xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
            <t:Table id="table" selectionMode="None" rows="{/}" visibleRowCount="3">
                <t:title>
                    <HBox>
                        <items>
                            <core:Icon src="sap-icon://cart" alt="Cart" size="1.25rem" />
                            <Title text="Suggested Contributions" titleStyle="H3" class="sapUiTinyMarginBeginEnd" />
                        </items>
                    </HBox>
                </t:title>
                <t:columns>
                    <t:Column width="11rem">
                        <t:template>
                            <Text text="{label}" />
                        </t:template>
                    </t:Column>
                    <t:Column width="11rem">
                        <Label text="Col1" />
                        <t:template>
                            <Input type="Number" value="{Col1}" />
                        </t:template>
                    </t:Column>
                    <t:Column width="11rem">
                        <Label text="Col2" />
                        <t:template>
                            <Input type="Number" value="{Col2}" />
                        </t:template>
                    </t:Column>
                    <t:Column width="12rem">
                        <Label text="Col3" />
                        <t:template>
                            <Input type="Number" value="{Col3}" />
                        </t:template>
                    </t:Column>
                    <t:Column width="12rem">
                        <Label text="Col4" />
                        <t:template>
                            <Input type="Number" value="{Col4}" />
                        </t:template>
                    </t:Column>                    
                    <t:Column width="12rem">
                        <Label text="State" />
                        <t:template>
                            <Text text="{parts:[{path:'Col1'},{path:'Col2'},{path:'Col3'},{path:'Col4'}], formatter: '.valStateFormatter'}" />
                        </t:template>
                    </t:Column>
                    <t:Column width="9rem">
                        <Label text="Total" />
                        <t:template>
                            <Input type="Number" enabled="false" value="{parts:[{path:'Col1'},{path:'Col2'},{path:'Col3'},{path:'Col4'}], formatter: '.totalFormatter'}" valueState="{parts:[{path:'Col1'},{path:'Col2'},{path:'Col3'},{path:'Col4'}], formatter: '.valStateFormatter'}" />
                        </t:template>
                    </t:Column>
                </t:columns>
            </t:Table>
        </mvc:View>
    </script>
    <script>
    // Controller definition
    sap.ui.define([
        "sap/ui/core/mvc/Controller",
        "sap/ui/model/json/JSONModel"
    ], function(Controller, JSONModel) {
        "use strict";
        return Controller.extend("local.controller", {
            onInit: function(oEvent) {
                this._setupContribModel();
            },
            _setupContribModel: function() {
                var myData = {
                    "Row1": {
                        "label": 'Row1',
                        "Col1": 50,
                        "Col2": 50,
                        "Col3": 0,
                        "Col4": 0
                    },
                    "Row2": {
                        "label": 'Row2',
                        "Col1": 0,
                        "Col2": 50,
                        "Col3": 50,
                        "Col4": 0
                    },
                    "Row3": {
                        "label": 'Row3',
                        "Col1": 0,
                        "Col2": 100,
                        "Col3": 0,
                        "Col4": 0
                    }
                };
                this.getView().setModel(new JSONModel(myData));
            },
            totalFormatter: function(v1,v2,v3,v4) {
                return Number(v1) + Number(v2) + Number(v3) + Number(v4);
            },
            valStateFormatter: function(v1,v2,v3,v4) {
                var val = this.totalFormatter(v1,v2,v3,v4);
                jQuery.sap.log.info('Total', val);
                return val === 100 ? 'Success' : 'Error';
            }
        });
    });
    jQuery.sap.log.setLevel(3)
    sap.ui.xmlview({
        viewContent: jQuery('#demoView').html()
    }).placeAt('content');
    </script>
</head>

<body class="sapUiBody" role="application">
    <div id="content"></div>
</body>

</html>
// Code goes here

/* Styles go here */