# DataGrid Totals?

**URL:** https://forum.kirupa.com/t/datagrid-totals/142898
**Category:** Uncategorized
**Created:** [April 1, 2005, 11:04am UTC](https://forum.kirupa.com/t/datagrid-totals/142898 "2005-04-01T11:04:46Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![darthmahon](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@darthmahon](https://forum.kirupa.com/u/darthmahon)
#### Post date: [April 1, 2005, 11:04am UTC](https://forum.kirupa.com/t/datagrid-totals/142898/1 "2005-04-01T11:04:46Z")

</div>

Hi,

I want to sum up a total of a specific column in a datagrid but am having problems, I’m using Flash MX 2004 Pro.

Here is what I have done:

Inserted a DataGrid, named it UserGrid.

Created a dynamic textfield called total.

I have the folllowing AS on frame 1:

[AS]  
import mx.controls.gridclasses.DataGridColumn;  
UserGrid.addColumn(new DataGridColumn(“Title”));  
UserGrid.addColumn(new DataGridColumn(“Quantity”));  
UserGrid.addColumn(new DataGridColumn(“Price”));

onClipEvent(enterFrame){  
sum = 0  
for(i=0; i\<UserGrid.getLength() ; i++) {  
trace(UserGrid.getItemAt(i).Price) //Here I output column values  
sum += Number(UserGrid.getItemAt(i).Price)  
}  
total.text = sum  
}  
[/AS]

I also have an add button that has the following AS:

[AS]  
on (release) {  
UserGrid.addItem({Title:“Product 1”, Quantity:“1”, Price:“27”});  
}  
[/AS]

Now, when I press the add button it puts a new entry into the datagrid, but I want it to calculate the total of all the rows in the Price column and insert them into the textfield total.

Not sure if my script on frame 1 is correct to be honest, gives me this in the textfield at the moment:

[AS]  
\_level0.total  
[/AS]

Any ideas?

Cheers,  
Chris
