I would be inclined to extend the datagrid and add a variable to handle this. You can compute the total from the dataprovider when it arrives from the server and pass that in as a bound variable to the custom datagrid. Example follows...
Application: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*"> <mx:Script> <![CDATA[ [Bindable] private var total:int = 101; private var dp:Array = [ {symbol: "ADBE", name: "Adobe Systems Inc.", dateIncorporated: "3/1/50"}, {symbol: "MACR", name: "Macromedia Inc.", dateIncorporated: "1/1/84"}, {symbol: "MSFT", name: "Microsoft Corp.", dateIncorporated: "11/24/71"}, {symbol: "IBM", name: "IBM Corp.", dateIncorporated: "9/14/63"} ]; ]]> </mx:Script> <local:MyExtendedDataGrid id="dg" initialize="dg.dataProvider = dp" verticalAlign="middle" total="{total}"> <local:columns> <mx:DataGridColumn headerText="Name" dataField="name" width="140"/> <mx:DataGridColumn headerText="Symbol" dataField="symbol" width="60" /> <mx:DataGridColumn headerText="Date" dataField="dateIncorporated" width="100" itemRenderer="ItemRenderers.TotalRenderer" /> </local:columns> </local:MyExtendedDataGrid> </mx:Application> MyExtendedDataGrid.as package { import mx.controls.DataGrid; public class MyExtendedDataGrid extends DataGrid { private static var _total:int; public function MyExtendedDataGrid() { super(); } public function set total(totalToSet:int):void {_total = totalToSet} public function get total():int {return _total} } } TotalRenderer.as <?xml version="1.0" encoding="utf-8"?> <mx:Label xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.controls.dataGridClasses.DataGridListData; override public function set data(value:Object):void { if(value != null) { super.data = value; text = value[DataGridListData(listData).dataField]; if(MyExtendedDataGrid(listData.owner).total == 100) { setStyle("color", "#FF0000"); } else { setStyle("color", "#0000FF"); } } } ]]> </mx:Script> </mx:Label> HTH Steve --- In [email protected], Neil Webb <nwebb.co...@...> wrote: > > Hi, just looking for advice on the most appropriate way to approach this (or > links to existing examples) :) > > I've got a DataGrid, and the items use a subclass of NumericStepper. This > stepper validates itself depending on the total of *all *items in that > column (i.e. it styles itself green if the column-total adds up to, say, > 100, or red if the column-total is <> 100). In other words, a single > itemRenderer needs knowledge of the values of ALL renderers in that column. > > I'm aware that itemRenderers should only take care of setting themselves, > due to recycling - (ie Adobe don't intend developers to get hold of a list > of all renderers, cycle over them and set properties on them externally). > > In this case however, in order to validate a *single *renderer I need to > know about the total of all renderers within a single column. Currently I > have things working - I give each renderer knowledge of its owner's > dataProvider - then, in the renderer's validation method I loop through all > items in the dp, total them up and set the style accordingly. > > However, this feels wrong. Also, it's not so bad if I have a > PercentageStepper, where I could hardcode the total as 100, but what about > columns where the user has a set amount of cash, and the total of all > Steppers must equal that cash-value? In that case, using my setup, > *each *renderer > also needs to know the total cash amount, which means setting it on each > renderer (easy to do, but again it feels wrong). > > So in a nutshell I guess I'm saying, what's the preferred way of validating > an itemRenderer, when the validation of that renderer depends on properties > of all the itemRenderers in that column? > > Thanks >

