tags:

views:

196

answers:

1

I have this datagrid which has columns with a NumericStepper as an itemEditor where the user can change the number of items he wants to buy. How can I calculate the sum of all cells when the user updates datagrid's values?

EDIT 1

My datagrid is about colors and sizes of a product. The columns are generated dynamically from this function

private function  getColumn(dataField:String, headerText:String,editable:Boolean) : DataGridColumn
 {
  var column:DataGridColumn = new DataGridColumn(dataField);
  column.headerText = headerText;
  column.width = 20;
  editable ? column.editable = true : column.editable = false;
  column.editorDataField = "value";
  column.itemEditor = new ClassFactory(ColorSizesFormRenderer);
  return column;
 }

and then I loop my xml http result

for each (var thisSize:XML in result.product.(@id == pId)..size) {
           _columns.push(getColumn("size"+thisSize,thisSize,true));
}

So how can I find the sum of all cells?

EDIT 2

I use this code to loop all my cells

protected function color_sizes_itemFocusOutHandler(event:DataGridEvent):void
 {
  total = 0;
  for each(var row:Object in color_sizes.dataProvider) {
     total += row.size28;
  }
 }

the row.size28 is generated dynamically. So it could be row.size29,row.size30 etc.

How can I loop through all my cells without knowing their data.property?

Thanks in advance

A: 

Your numeric stepper should show a bindable property value from the [data] row you display. Then you just parse the dataProvider of the datagrid and make the sum of that data.property.

for ex:

class MyObject 
{
    [Bindable]
    var itemsNo:int = 0;
    var productName:String = ""; 
}

The datagrid will have a NumericStepper custom column that will take the value of {data.itemsNo}

At the end just count all itemsNo from the datagrid.dataProvider items

Adrian Pirvulescu