Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-27-2006, 03:58 PM   #1
ljonny18
Registered User
 
Join Date: Oct 2006
Posts: 112
Default calculated DG columns

Hi I am wondering if someone can help me….. I think what I am trying to do (and my actual problem) is quite simple, although I am the way going about it is possibly slightly different to the “norm” – so let me try to explain ;)

I have a dataGrid (“myDG”) containing different columns, two of which are calculated columns that I want to change every time the other values within the dataGrid change

Some example code:

<mx:DataGrid editable="true" id="myDG " dataProvider="{myDGProvider}" change=”performCalcs()”>
<mx:columns>
<mx:DataGridColumn id=”colA” dataField="resultA" headerText="result A"/>
<mx:DataGridColumn id=”colB” dataField="resultB" headerText="result B"/>
<mx:DataGridColumn id=”colC” dataField="resultC" headerText="result C"/>
<mx:DataGridColumn id=”colD” dataField="resultD" headerText="result D"/>
</mx:columns>
</mx:DataGrid>

I also have a combo box that consists of two different statuses, and I want to perform different calculations to the dataGrid columns depending on the selected status.

The 2 statuses are e.g. “calculation 1” and “calculation 2” and have the following conditions:

If “calculation 1” is selected, then I want “colD” = colA + colB + colC.
Else
If “calculation 2” is selected, then I want “colD” = colA - colB - colC.
Etc………

<mx:ComboBox id="myCB" change="changeDiscountCode()" change=”performCalcs()”>
<mx:dataProvider>
<mx:Array>
<mx:String>calculation 1</mx:String>
<mx:String>calculation 2</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>

The dataGrid is populated by an array acting as a dataProvider – the dataGrids dataProvider starts off empty and there is a button where the user can “add” a row to the dataGrid etc…:

<mx:Button label="Add Row" click="addRow ()"/>

public function addRow () {
var newRow:Object = new Object();
myDG_dg.addItem(newRow);
}

etc… with the object “newRow” assigning a default value to each column and successfully adding a new row to the dataGrid.

As you can also see, I have added a “change” property to the dataGrid and comboBox to perform my calculations:

public function performCalcs () {
if(myCombo.text = “calculation 1”) {
for(var x:int=0;x<DG_ myDGProvider.length;x++) {
myDG[x].colD = myDG[x].colA + myDG[x].colB + myDG[x].colC;
}
}
else if(myCombo.text = “calculation 2”) {
for(var x:int=0;x<DG_ myDGProvider.length;x++) {
myDG[x].colD = myDG[x].colA - myDG[x].colB - myDG[x].colC;
}
}

}

etc………….

this all works fine….. but the calculations only take place / change when the actual columns are directly changed….
I additionally want to automatically perform the DG column calculations when the comboBox is changed thus automatically changing and performing the DG calculations as the comboBox value is changed, without having to then change a value within the DG for the calculations to take place etc……

Is there some way I can go about doing this??? Do I have to refresh the dataProvider somehow???


Thanks,
Jon.
ljonny18 is offline   Reply With Quote
Old 11-29-2006, 04:56 PM   #2
CDHBookingEdge
Registered User
 
Join Date: Oct 2006
Posts: 383
Send a message via MSN to CDHBookingEdge
Default

Hey Jonny ;-)

If I understood you as far as what you want then, I think what you need to to is catch the combo box change event. The livedocs for combobox says:
Quote:
Dispatched when the ComboBox contents changes as a result of user interaction: when the selectedIndex or selectedItem property changes, and, if the ComboBox control is editable, each time a keystroke is entered in the box.
That's pretty much what you want to do right? So if you catch that event and then in the handler for it you call your performcalc code then bing bang bam..it's working for ya right? Now it could be another event might be better like close or something to be really make it work properly and so you know the user actually made the choice and isn't just "fiddling with things" but that's pretty much the idea as I see it.

Christopher
CDHBookingEdge is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
tsunami tutorial (again!) - multiple columns! doobie ActionScript 1.0 (and below) 7 04-28-2007 01:47 AM
[flash 8]sort movieclips into columns... uni009 ActionScript 2.0 1 12-09-2005 07:43 AM
display xml results in columns (NOT datagrid) erova ActionScript 1.0 (and below) 1 05-27-2005 03:44 PM
DataGrid and limiting columns jkemrich Components 1 12-30-2003 06:00 PM
dynamically creating columns of text octothorp Simple Stuff (Newbies) 0 03-04-2002 04:22 PM


All times are GMT. The time now is 04:37 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.