Quantcast
Channel: SCN: Message List - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 8124

Re: Sum of Odata values in a table

$
0
0

Hi Stefan

My initial answer would be to push the heavy lifting back to the Application server, I would normally do this type of operation at the database as mentioned above via SQL and encapsulate in a Service Operation or Entity Action which you can call via the ODataModel.

 

I recently had to do something very similar to what you are asking, there were additional requirments which meant the calculation had to be done on the client side, to get round table paging, I solved the calculation by doing a generic binding which read the whole entity dataset upfront instead of in chunks as needed,  I deferred the table binding till after the calculation to ensure the data was retrieved only once, below is a simple example.

 

// get a list of all order
var oBindings = oModel.bindList('/Orders'); 
// call the $count to get total lines to be read
len = oBindings.getLength();
// set the model limit to $count to ensure all read at once
oModel.setSizeLimit(len);
// attach a handler and do the calculation on returned contexts
oBindings.attachChange(function(oEvent){     aContexts = oEvent.getSource().getContexts(); // returned list of orders     for (var i = 0, len = totals.length; i < len; i++) {       var sum += aContexts[i].getObject().OrderTotal; // do calculation     }
oTable.bindRows('/Orders'); //use the extracted list to bind to table
});
// get all context from backend
oBindings.getContexts();

Here is a simple example creating a total for all Northwind Order_Details 2000+ of them JSBin - OData totalling all orders

 

hth

jsp


Viewing all articles
Browse latest Browse all 8124

Trending Articles



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