You can use the grid's itemEditEnd handler to update the total after
the user has finished editing the item. Also, set the grid's
editable property to true and each column's editable property as
desired.
If you want to actively track changes to the editor as the user
makes them instead of after the user has finished editing the item,
you may need to break the NumericStepper out as a component, and use
the change event to trigger your function.
<mx:DataGrid id="grid" dataProvider="{myDP}" editable="true"
textAlign="center"
itemEditEnd="callLater(calculateTotal)">
<mx:columns>
<mx:DataGridColumn headerText="Product" dataField="name"
editable="false"/>
<mx:DataGridColumn id="qtyChanger" headerText="Qty"
dataField="qty"
rendererIsEditor="true"
itemRenderer="mx.controls.NumericStepper" editorDataField="value"/>
<mx:DataGridColumn headerText="Price" dataField="price"
editable="false"/>
</mx:columns>
</mx:DataGrid>
--- In [email protected], "s_hernandez01"
<[EMAIL PROTECTED]> wrote:
>
> Can anyone tell me how I can get my event listener to update the
total
> when the quantity is changed using the numericStepper inside a
datagrid?
>
> Thanks
>
> Sal
>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
> layout="absolute" xmlns="*" creationComplete="calculateTotal()">
>
>
> [Bindable]
> public var total:Number=0;
> [Bindable]
> public var numProducts:int=0;
> [Bindable]
> public var myDP:ArrayCollection = new ArrayCollection();
>
> public function calculateTotal():void{
> var t:Number = 0;
> var n:Number = 0;
> for(var i:int = 0; i < myDP.length; i++){
> n += myDP[i].qty;
> t += myDP[i].price * myDP[i].qty;
> }
> total = t;
> numProducts = n;
> }
>
> public function qtyChangeListener():void{
> qtyChanger.addEventListener("change", calculateTotal);
> }
>
> <mx:DataGrid id="grid" dataProvider="{myDP}" textAlign="center">
> <mx:columns>
> <mx:DataGridColumn headerText="Product" dataField="name"/>
> <mx:DataGridColumn id="qtyChanger" headerText="Qty" dataField="qty"
> rendererIsEditor="true" itemRenderer="mx.controls.NumericStepper"
> editorDataField="value"/>
> <mx:DataGridColumn headerText="Price" dataField="price"/>
> </mx:columns>
> </mx:DataGrid>
>
> <mx:Text text="{total}"/>
>
> </mx:Application>
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/flexcoders/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/