That example is posted:

http://www.cflex.net/showfiledetails.cfm?ChannelID=1&Object=File&objectI
D=568

 

Tracy

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Tracy Spratt
Sent: Friday, December 01, 2006 1:27 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: Can't get value after labelfunction

 

Absolutely.  Use a custom item object as I proposed earlier.  I'll have
an example on CFLEX.NET in an hour or so.  

 

Tracy

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of bsdensmore
Sent: Friday, December 01, 2006 8:44 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Can't get value after labelfunction

 

Thanks for trying Tracy. Any ideas of what route I should go?

Thanks,
Ben

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
, "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> While this method works, I do not think it is a good solution.
> 
> 
> 
> I decided to add a "simple" functionality of displaying the total
weight
> value of the items in the calculated column. But the fact that the
> column's values are calculated by the itemRenderer presents many
> problems.
> 
> 
> 
> Because the renderers only calculate the visible rows, we can never
get
> a total using those calculations. Instead, we have to do the full
> caclulation of net_price for each item and then add it to the sum. 
> 
> 
> 
> So if we want to update the total weight when a user updates the
> quantity value, we have a problem deciding when to invoke the
> calculation. On the itemEditEnd event, the quantity property has been
> updated but the item renderer has not yet run so the net_weight
property
> is not yet calculated.
> 
> 
> 
> I attempted to determine the last item rendered, but this became a
> problem itself.
> 
> 
> 
> In all, I would do it differntly.
> 
> 
> 
> Tracy
> 
> 
> 
> 
> 
> 
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of Tracy Spratt
> Sent: Thursday, November 30, 2006 5:23 PM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> Subject: RE: [flexcoders] Re: Can't get value after labelfunction
> 
> 
> 
> Ok, I have it working
> 
> 
> 
> First your dataProvider item objects do NOT have properties for all
> three columns, only the item weight column.
> 
> 
> 
> So this condition:
> 
> if (value.claimed != null ...
> 
> will always be false and the calculation will not happen.
> 
> 
> 
> Add the other two columns to the dataprovider item object, defaulted
to
> 0, and everything works, even when you update the quantity.
> 
> theData = new ArrayCollection(
> 
> [{each_wt:30,quantity:1,net_wt:0},
> 
> {each_wt:95,quantity:0,net_wt:0},
> 
> {each_wt:105,quantity:9,net_wt:0}]);
> 
> 
> 
> I am going to modify your example some and post it on CFLEX.
> 
> 
> 
> Tracy
> 
> 
> 
> ________________________________
> 
> From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
[mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of bsdensmore
> Sent: Thursday, November 30, 2006 4:07 PM
> To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] Re: Can't get value after labelfunction
> 
> 
> 
> yes, they do. 
> 
> I'm just doing a very small example to get my head around this. I
> actually took the ClassFactory stuff out and went to using the
> itemrenderer as is. It works but now I'm running into the issue of my
> datagrid losing it's state when you scroll.
> 
> This is what my main Application looks like, 
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > "
> layout="absolute" creationComplete="populate();">
> <mx:Script>
> <![CDATA[
> import mx.collections.ArrayCollection;
> import mx.utils.*;
> import mx.controls.Alert;
> 
> 
> 
> [Bindable] public var theData:ArrayCollection;
> 
> 
> public function populate():void 
> {
> 
> theData = new ArrayCollection([{Net_Wt:30},{Net_Wt:65}]);
> 
> }
> 
> 
> public function show():void
> {
> Alert.show(theData.getItemAt(0).net_lbs);
> }
> 
> ]]>
> </mx:Script>
> 
> <mx:DataGrid x="85" y="147" id="myDataGrid" dataProvider="{theData}"
> editable="true">
> <mx:columns>
> <mx:Array>
> <mx:DataGridColumn headerText="Net Weight" dataField="Net_Wt"
> editable="false"/>
> <mx:DataGridColumn headerText="Cases Claimed" dataField="claimed"
> editable="true" />
> <mx:DataGridColumn headerText="Net Lbs Claimed" dataField="net_lbs"
> editable="false" itemRenderer="calculatedItemRenderer"/>
> </mx:Array>
> </mx:columns>
> </mx:DataGrid>
> <mx:Button x="205" y="306" label="Button" id="myBtn" click="show()"/>
> 
> </mx:Application>
> 
> My ItemRenderer looks like:
> <?xml version="1.0" encoding="utf-8"?>
> <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> 
> <http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> > "
width="72"
> height="20" horizontalAlign="center">
> <mx:Script>
> <![CDATA[
> import mx.controls.listClasses.ListData;
> import mx.controls.Alert;
> import mx.utils.StringUtil;
> import flash.events.Event;
> import mx.controls.dataGridClasses.DataGridListData;
> 
> override public function set data(value:Object):void
> {
> if (value != null) {
> super.data = value;
> if (value.claimed != null &&
> StringUtil.trim(value.claimed) != "") {
> var total:Number = value.Net_Wt * value.claimed;
> myText.text = total.toString();
> value.net_lbs = total;
> }
> }
> }
> 
> 
> ]]>
> </mx:Script>
> 
> 
> <mx:Text id="myText" />
> 
> </mx:HBox>
> 
> Ben
> 
> --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> , "Tracy Spratt" <tspratt@> wrote:
> >
> > First: Does your dataProvider (the item objects specifically) have a
> > property for each of the three columns?
> > 
> > Tracy
> > 
> > 
> > 
> > ________________________________
> > 
> > From: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> ] On
> > Behalf Of bsdensmore
> > Sent: Thursday, November 30, 2006 1:58 PM
> > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com> 
> > Subject: [flexcoders] Re: Can't get value after labelfunction
> > 
> > 
> > 
> > I keep going in circles with this. If I don't use the ClassFactory I
> > can get the calculations to work but I can't figure out how to send
> > the value back to the dataProvider. If I try to use the ClassFactory
> > and set my properties through the ClassFactory properties nothing is
> > being passed into the itemRenderer. 
> > 
> > This is driving me nuts.
> > 
> > My DataGrid has 3 Fields Case_Weight, Cases_Claimed and Net_Lbs. 
> > Net_Lbs uses the item renderer which is a "Text" Custom Component.
> > 
> > When the dataProvider is populated only Case Weight has a value. The
> > other 2 fields are blank. Cases_Claimed is editable and based on
what
> > is entered in there it multiplies Case_Weight and Cases_Claimed and
> > sets Net_Lbs to the total amount. Should I be using something other
> > than a "Text" component?
> > 
> > Thanks,
> > Ben
> > 
> > --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com>
> > , "Tracy Spratt" <tspratt@> wrote:
> > >
> > > An item renderer will certianly work and there are a lot of
examples
> > > available. The process will be exactly the same as for the
checkbox
> > > renderer yo have worked with, so it will be much easier this time
> > > (assuming you got the checkbox renderer working correctly! If not,
I
> > > have an example on cflex.net.
> > > 
> > > 
> > > 
> > > But actually what I was suggesting was a bit different. I think it
> was
> > > Anatole who mentioned using this technique as well, but what you
> would
> > > do is use the raw result data to build an arrayCollection of new
> > custom
> > > objects. The custom class would have the caluclated properties
built
> > in,
> > > and you would use this ArrayCollection as the dataProvider.
> > > 
> > > 
> > > 
> > > Since clearly your raw dataProvider does not have the calculated
> > > property/field in it, you would have to somehow add this property
to
> > the
> > > dataProvider anyway, to be able to set it from your renderer.
> > > 
> > > 
> > > 
> > > If you build the custom objects up front, you would not need the
> > > renderer, and the class could be optimized to simplify building
the
> > > structure you are going to send back to the server. 
> > > 
> > > 
> > > 
> > > This technique leaves labelFunction and even custom renderers
> > available
> > > to modify the presentation, without mucking with the base data.
> > > 
> > > 
> > > 
> > > This may sound inefficient, but I have been doing it on my apps a
> lot,
> > > and have found that for this kind of non-visual stuff, even Flash
> > Player
> > > 7 was blazingly fast. The improvements in 8, 9 make it even
faster.
> > > 
> > > 
> > > 
> > > Tracy
> > > 
> > > 
> > > 
> > > ________________________________
> > > 
> > > From: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com>
> > [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com>
> > ] On
> > > Behalf Of bsdensmore
> > > Sent: Thursday, November 30, 2006 8:32 AM
> > > To: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com> 
> > > Subject: [flexcoders] Re: Can't get value after labelfunction
> > > 
> > > 
> > > 
> > > Thanks Ben and Tracy,
> > > I was thinking that I might need to use an item renderer but was
> > > hoping to not have to. I just struggled with using them to
implement
> a
> > > checkbox into the DataGrid. I still don't get how to write them
> > > effectively. I need to do some more reading to try and get a
better
> > > grip.
> > > 
> > > What type of component should be used for this? Just a Text or
> Label?
> > > 
> > > Thanks,
> > > Ben
> > > 
> > > --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com>
> > <mailto:flexcoders%40yahoogroups.com>
> > > , "ben.clinkinbeard"
> > > <ben.clinkinbeard@> wrote:
> > > >
> > > > Tracy is right, you should use an itemRenderer for this.
> > > > calculatedValueRenderer should override the data method (like
all
> > good
> > > > little renderers do :)) and in the method retrieve the values to
> be
> > > > calculated as well as updating the calculated value in the
> > > > dataProvider. Using the ClassFactory approach that we've
> discussed,
> > > > apossible properties property may look something like this:
> > > > 
> > > > myCalcFactory.properties = {sourceFieldA: "quantity",
> sourceFieldB:
> > > > "price", totalField: "totalItemPrice"};
> > > > 
> > > > HTH,
> > > > Ben
> > > > 
> > > > 
> > > > --- In flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com> 
> > > <mailto:flexcoders%40yahoogroups.com> , "Tracy Spratt" <tspratt@>
> > wrote:
> > > > >
> > > > > I don't think labelFunction is intended to update the
> > dataProvider.
> > > I
> > > > > don't see how it possibly could, since it can use multiple
> columns
> > > and
> > > > > does not even have to have a dataProvider property associated
> with
> > > it.
> > > > > 
> > > > > 
> > > > > 
> > > > > If you want this, I heard of a technique that uses a custom
item
> > > object,
> > > > > with calculated properties like that built in, and when result
> > data
> > > is
> > > > > received, one loops over the raw data creating custom objects
> for
> > > each,
> > > > > and assigning them to the dataProvider. This also lets you use
> > > > > labelFunction to change the way the data is displayed, without
> > > messing
> > > > > up the underlying data. Currency formatting, for example.
> > > > > 
> > > > > 
> > > > > 
> > > > > Just brainstorming.
> > > > > 
> > > > > 
> > > > > 
> > > > > Tracy
> > > > > 
> > > > > 
> > > > > 
> > > > > ________________________________
> > > > > 
> > > > > From: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com> 
> > > <mailto:flexcoders%40yahoogroups.com> 
> > > [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com>
> > <mailto:flexcoders%40yahoogroups.com>
> > > ] On
> > > > > Behalf Of bsdensmore
> > > > > Sent: Wednesday, November 29, 2006 5:23 PM
> > > > > To: flexcoders@yahoogroups.com
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com> 
> > <mailto:flexcoders%40yahoogroups.com>
> > <mailto:flexcoders%40yahoogroups.com>
> > > 
> > > > > Subject: [flexcoders] Can't get value after labelfunction
> > > > > 
> > > > > 
> > > > > 
> > > > > I have 2 DataGridColumns that use a labelfunction to multiply
a
> > > couple
> > > > > of fields and display the value in another column. For some
> reason
> > > > > after the field is updated with the total I can't get at that
> > value.
> > > 
> > > > > 
> > > > > The dataProvider that the DataGrid is bound to is a query
result
> > > that
> > > > > is converted to an ArrayCollection. When the ArrayCollection
is
> > > > > initially populated this field is blank. So, I'm guessing that
> > after
> > > > > the labelfunction executes it doesn't update the
ArrayCollection
> > to
> > > > > hold the newly calculated value? 
> > > > > 
> > > > > How can I go about updating the ArrayCollection so I can save
it
> > to
> > > a
> > > > > database table. I swear I had this working.
> > > > > 
> > > > > Thanks,
> > > > > Ben
> > > > >
> > > >
> > >
> >
>

 

Reply via email to