/** * 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; this.numbersCount--; } } ,after: function (row) { var value = this.getRowValue (row); if (value !== null) { this.sum += value; this.numbersCount++; } } ,init: function () { this.sum = 0; this.numbersCount = 0; } ,done: function () { if (this.numbersCount > 0) this.value = this.sum; else this.value = null; } });