У вас есть два способа сделать это. Первый способ - вычислить итоговое значение в вашем объекте данных следующим образом:
package
{
public class GridData
{
[Bindable]
public var mark1:int;
[Bindable]
public var mark2:int;
[Bindable]
public var mark3:int;
public function get total():int
{
return mark1 + mark2 + mark3;
}
}
}
А наше приложение:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute" xmlns:local="*" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:ArrayCollection id="dataList">
<mx:source>
<mx:Array>
<local:GridData mark1="5" mark2="7" mark3="14" />
<local:GridData mark1="4" mark2="2" mark3="4" />
<local:GridData mark1="15" mark2="72" mark3="1" />
<local:GridData mark1="25" mark2="37" mark3="15" />
<local:GridData mark1="55" mark2="1" mark3="6" />
<local:GridData mark1="43" mark2="7" mark3="12" />
<local:GridData mark1="11" mark2="11" mark3="22" />
</mx:Array>
</mx:source>
</mx:ArrayCollection>
<mx:VBox horizontalCenter="0" verticalCenter="0">
<mx:DataGrid dataProvider="{dataList}" id="dg">
<mx:columns>
<mx:DataGridColumn dataField="mark1" headerText="mark1" />
<mx:DataGridColumn dataField="mark2" headerText="mark2" />
<mx:DataGridColumn dataField="mark3" headerText="mark3" />
<mx:DataGridColumn dataField="total" headerText="total" />
</mx:columns>
</mx:DataGrid>
<mx:Form enabled="{dg.selectedItem}">
<mx:FormItem label="mark1">
<mx:NumericStepper change="dg.selectedItem.mark1 = event.currentTarget.value" maximum="10000"
minimum="0" value="{dg.selectedItem.mark1}" />
</mx:FormItem>
<mx:FormItem label="mark2">
<mx:NumericStepper change="dg.selectedItem.mark2 = event.currentTarget.value" maximum="10000"
minimum="0" value="{dg.selectedItem.mark2}" />
</mx:FormItem>
<mx:FormItem label="mark3">
<mx:NumericStepper change="dg.selectedItem.mark3 = event.currentTarget.value" maximum="10000"
minimum="0" value="{dg.selectedItem.mark3}" />
</mx:FormItem>
</mx:Form>
</mx:VBox>
</mx:Application>
Второй способ - использовать функцию метки. Итак, наш объект данных:
package
{
public class GridData
{
[Bindable]
public var mark1:int;
[Bindable]
public var mark2:int;
[Bindable]
public var mark3:int;
}
}
и наше приложение:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="absolute" xmlns:local="*" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
private function calculateTotal(data:GridData, column:DataGridColumn):String
{
return (data.mark1 + data.mark2 + data.mark3).toString();
}
]]>
</mx:Script>
<mx:ArrayCollection id="dataList">
<mx:source>
<mx:Array>
<local:GridData mark1="5" mark2="7" mark3="14" />
<local:GridData mark1="4" mark2="2" mark3="4" />
<local:GridData mark1="15" mark2="72" mark3="1" />
<local:GridData mark1="25" mark2="37" mark3="15" />
<local:GridData mark1="55" mark2="1" mark3="6" />
<local:GridData mark1="43" mark2="7" mark3="12" />
<local:GridData mark1="11" mark2="11" mark3="22" />
</mx:Array>
</mx:source>
</mx:ArrayCollection>
<mx:VBox horizontalCenter="0" verticalCenter="0">
<mx:DataGrid dataProvider="{dataList}" id="dg">
<mx:columns>
<mx:DataGridColumn dataField="mark1" headerText="mark1" />
<mx:DataGridColumn dataField="mark2" headerText="mark2" />
<mx:DataGridColumn dataField="mark3" headerText="mark3" />
<mx:DataGridColumn labelFunction="calculateTotal" headerText="total" />
</mx:columns>
</mx:DataGrid>
<mx:Form enabled="{dg.selectedItem}">
<mx:FormItem label="mark1">
<mx:NumericStepper change="dg.selectedItem.mark1 = event.currentTarget.value" maximum="10000"
minimum="0" value="{dg.selectedItem.mark1}" />
</mx:FormItem>
<mx:FormItem label="mark2">
<mx:NumericStepper change="dg.selectedItem.mark2 = event.currentTarget.value" maximum="10000"
minimum="0" value="{dg.selectedItem.mark2}" />
</mx:FormItem>
<mx:FormItem label="mark3">
<mx:NumericStepper change="dg.selectedItem.mark3 = event.currentTarget.value" maximum="10000"
minimum="0" value="{dg.selectedItem.mark3}" />
</mx:FormItem>
</mx:Form>
</mx:VBox>
</mx:Application>