Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8357

Re: How to get formatter result into model

$
0
0

Like I said the formatter calculates the correct values and inputs them onto the table I just want that new value to be on the model too instead of the old value and it's only the total column that uses the formatter, the other columns don't and the model is updated when I type in a new value in the cell of the table.

 

So when the formatter updates the total from 10 to 20, it shows 20 on the table but still 10 on the model.

 

Json Model looks like this
{    "success": "true",    "msg": "Timesheets available",    "entries": [        {            "rework": "",            "monday": 2.5,            "tuesday": 3.5,            "wednesday": 4,            "thursday": 0,            "friday": 0,            "saturday": 0,            "sunday": 0,            "total": 10,            "sel": ""        },        {            "monday": 1.25,            "tuesday": 0,            "wednesday": 0,            "thursday": 0,            "friday": 0,            "saturday": 0,            "sunday": 0,            "total": 1.25,            "sel": ""        }    ]
}

Example of column

 

       oTable.addColumn(new sap.ui.table.Column({           label: new sap.ui.commons.Label({text: "Monday"}),           template: new sap.ui.commons.TextField({value: {path: "monday", type: oFloat},  change : function(oEvent){               oController.validateNumber(oEvent);               oController.handlePressMonday();               oController.updateTotal(oEvent);               oController.handlePressTotal();                     }                 }),           sortProperty: "monday",           filterProperty: "monday",           width: "60px"    }));       oTable.addColumn(new sap.ui.table.Column({        label: new sap.ui.commons.Label({text: "Total"}),        template: new sap.ui.commons.TextField("txtField",{
//         editable: false,        value: {          parts: [{ path: "monday"}, {path: "tuesday"}, {path: "wednesday"}, {path: "thursday"}, {path: "friday"}, {path: "saturday"}, {path: "sunday"}],           formatter: formatTotal      },             }),        width: "60px"
 }));        var oModel = sap.ui.getCore().getModel();        oTable.setModel(oModel);        oTable.bindRows("/entries");

 

My formatter that calculates the values in my controller

 

 var formatTotal = function(monday, tuesday, wednesday, thursday, friday, saturday, sunday) {  var total = formatDec2(getLineTotal(monday, tuesday, wednesday, thursday, friday, saturday, sunday));         return total;     };     var getLineTotal = function(monday, tuesday, wednesday, thursday, friday, saturday, sunday) {         return parseFloat(monday) + parseFloat(tuesday) + parseFloat(wednesday) + parseFloat(thursday) + parseFloat(friday) + parseFloat(saturday) + parseFloat(sunday);     };     var formatDec2 = function(value) {         if (isNaN(value)) {             return 0;         }         var numberFormat = sap.ui.core.format.NumberFormat.getIntegerInstance({             maxIntegerDigits: 10,             minIntegerDigits: 1,             maxFractionDigits: 2,             minFractionDigits: 2,             groupingEnabled: true         });         return numberFormat.format(value);     };

Viewing all articles
Browse latest Browse all 8357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>