Here is a simple calculation patch which adds 'formula' property to the grid cells. The formula should be a string, use normal javascript syntax and can include any global or Math object functions. The function column(i) is used to refer to any cell in the current row.
if (!this._notify[src]){
this._notify[src] = {};
}
this._notify[src][col] = true;
}
},
onCellValueChanged: function(value, col, row){
if (this._notify && this._notify[col]){
for (var i in this._notify[col]){
this.raiseEvent('onCellValueChanged', '', i, row);
}
}
},
onCellValidated: function(text, col, row){
var f = this.getCellFormat(col, row);
var v = f ? f.textToValue(text) : text;
function formatted(c, r){
var v = this.getCellValue(c, r);
var f = this.getCellFormat(c, r);
return f ? f.valueToText(v) : v;
}
var str = new AW.Formats.String;
var num = new AW.Formats.Number;
num.setTextFormat('#,###.##');
var obj = new AW.UI.Grid;
obj.setHeaderText(myHeaders);
obj.setCellData(myCells);
obj.setCellFormat([str, num, num, num]);
obj.setColumnCount(4);
obj.setRowCount(3);
obj.setCellEditable(true);
obj.setCellFormula('column(1)*column(2)', 3); // calc total in column-3
document.write(obj);
</script>
</body>
</html>
Alex (ActiveWidgets)
Wednesday, October 10, 2007
Note, that it is also possible to use custom functions in formulas -
function myFunction(a, b){
return a*0.1 + b;
}
obj.setCellFormula('myFunction(column(1), column(2))', 3); // calc in column-3
Alex (ActiveWidgets)
Wednesday, October 10, 2007
Hi,
Will this patch be part of main library in 2.5 release.
Regards
Girish
Girish Khemani, Fidelity India
Wednesday, October 10, 2007
I don't know yet. Do you think it is a good idea to include this 'cell formula' code into the standard package? Or I should leave it separately as an add-on?
Alex (ActiveWidgets)
Friday, October 12, 2007
Hi Alex,
The size of the library increases every release, which is natural for any software.
I had looked about some time back on how I could reduce the size of aw.js by removing features I don't use.
One example is that I can remove the lines at the end of aw.js beginning with AW.HTTP.Request=, AW.CSV.Table= and AW.XML.Table= as I use another library to handle my XML HTTP requests and don't use csv and xml tables.
Right now I use the entire aw.js, but in future, if I need to crunch the size of the javascript in my application, I was thinking of the above and more removals in other .js files I use.
If this cell formula code is included, would it be possible to include it in a way in which it can be removed easily if we are not using the feature ?
Thanks,
Ankur
Ankur Motreja
Friday, October 12, 2007
Maybe you could include an "AW Lite" for basic functionality... and then "AW Standard" which includes these functions. I feel that when you have a grid like this it's important to offer as many functions as possible.
Ed
Thursday, October 18, 2007
Hello,
Is it possible to set formulas in a header row instead of a cell row?
Regards,
Brad
Tuesday, October 23, 2007
how about i want to calculate the row and put it into my footer? please help me..alex