0
votes

I have a Master-Detail view on SAPUI5, using oData. On the Detail, I have a sap.ui.table.Table and I want to calculate the sum of each column and place it on a sap.m.Label, which is placed at the footer of the table.

I am running a function at the busyStateChanged event of the table, responsible for calculating the sum by adding the values the column cells. The problem is that when the event is triggered, the binding context is not available yet. I have tried placing the code in the _onBindingChange() method, but even though the binding context is available then, the values from the oData are not visible yet in the sap.m.Input fields that exist on the table, therefore the sum is calculated wrongly.

As a workaround I have used a Promise to wait for a few ms before calculating the sums (triggered from the busyStateChanged event). The code looks like this:

tableAfterRender: function() {
    var that = this;
    var waitSomeTime = this.sleep(50);
    waitSomeTime.then(function() {
        that.calcSums();
    });
},

sleep: function(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

The problem is that Promises do not work with Internet Explorer. Is there an alternative approach (e.g. an alternative to Promise -preferably not a worker, since it requires a new file from what I have read- or a sap.ui.table.Table event) to wait for data loading before calculating the sums?

Thank you very much!

1
Are you obtaining the values from the Input field through its actual value property or getting it from the binding you use?Daniel Almeida
Thanks for your reply! I am getting it from the Input field.Iakovos Gu
Have you tried obtaining the values from the binding while using your _onBindingChange() solution? Since you said the bindingContext is available by then, even though the value is not visible on the actual Input field, it should be retrievable through the model itself.Daniel Almeida
Yes this is right, however I want to perform the calculation onlivechange. I found the solution to the issue (see my answer below). Thank you very much for the tips :)Iakovos Gu

1 Answers

0
votes

Found the solution:

The code should look like this:

tableAfterRender: function() {
    var that = this;

    setTimeout(function() {
        that.calcSums();
    });
}

I removed sleep completely and calculate the sum in setTimeout(). It works perfectly for me.