0
1
Fork 0
hedera-web-mindshore/js/db/calc-sum.js

50 lines
666 B
JavaScript

/**
* Computes a sum of data in the model.
**/
Db.CalcSum = new Class
({
Extends: Db.Calc
,Tag: 'db-calc-sum'
,getRowValue: function (row)
{
var value;
if (this._func)
{
this._set.row = row;
value = this._func (this._set);
}
else
value = this._model.getByIndex (row, this.columnIndex);
return value;
}
,before: function (row)
{
var value = this.getRowValue (row)
if (value !== null)
this._sum -= value;
}
,after: function (row)
{
var value = this.getRowValue (row);
if (value !== null)
this._sum += value;
}
,init: function ()
{
this._sum = 0;
}
,done: function ()
{
this.value = this._sum;
}
});