What you could do… if your myDP is an ArrayCollection or one of the collection classes you could add a listener to the change event.  That way any time the dataProvider changes (the change event on the Collection itself can let you know if an item was added, removed or updated) you can recalculate the totals.  That way your total will always be in synch with your data without having to manually recalculate the total.

 


From: [email protected] [mailto:[email protected]] On Behalf Of s_hernandez01
Sent: Wednesday, October 25, 2006 3:14 PM
To: [email protected]
Subject: [flexcoders] Datagrid Change Function

 

Hey Flexers

I created a datagrid to represent a shopping cart. Now, I'm having a
problem updating the total when the quantity is changed. Right now it
just gives the total because I have the quantity set to 1, but if the
users types in a different quantity I want it to update the total. If
anybody has any suggestions, I'd appreciate it. Below is my calculate
function and my datagrid.

Thanks
Sal

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;
}

<mx:DataGrid width="100%" height="250" dataProvider="{myDP}"
textAlign="center" id="cartGrid">
<mx:columns>
<mx:DataGridColumn id="qty" headerText="Qty"
rendererIsEditor="true" dataField="qty"
itemRenderer="mx.controls.TextInput" editorDataField="value" width="24"/>
<mx:DataGridColumn headerText="Price" width="35"
dataField="price" labelFunction="myLabelFunction"/>

</mx:columns>
</mx:DataGrid>

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to