Skip to Content
author's profile photo Former Member
Former Member

How to calculate table COLUMN total


I've been able to calculate row totals for each column but now I'd like to calculate a total per column for all the rows in the table.

So say if i had a table with columns mon-fri

I'd have some form of a footer with a total then for mon, and another for tues, and another for wed, etc..

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 10, 2014 at 04:00 AM


    This might help.

    var oTable= sap.ui.getCore().byId("<<Table Id>>");

    var nRows= oTable.getBinding("rows").getLength();

    var nSum= 0;

    for(var i=0; i<nRows; i++){

    var oContext= oTable.getContextByIndex(i);

    nSum+= oContext.getProperty("<<Col Name as defined in the model>>");


    Here I am assuming that the data type of columns "Mon", "Tues" in the model is of type 'Number'.



    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      I think what's happening is that the model isn't ready binding the table because my code is very similar to yours but I have to put an alert in the $( document ).ready function for it to work, so with the alert in it works fine.

      init: function(){ var oUrl = 'http://restservice/data/get_data'; var oParams = {"WEEK_ENDING":"20140302"}; var oModel = new myJSONModel; oModel.loadData(oUrl, oParams, true, 'POST', false, false, ''); //This works sap.ui.getCore().setModel(oModel); oModel.setSizeLimit(1000); }, onInit: function() {


      var that=this;

      $( document ).ready(function() {

      alert("doc ready");




Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.