Thanks Martin, I'm not making the renderer editable, but the business logic requires custom formatting, and the default formatters aren't sufficient.
I agree less complicated is much better though, philosophically. I hate to use the ADG instead of the spark DataGrid for that reason. Do I have to do anything special to avoid memory leaks using the ADG in this way? For example: http://ordinarybugs.blogspot.com/2010/07/flex-advanceddatagrid-memory-leak.html I think that one applies to dynamic columns, correct me if I'm wrong. ----- Original Message ----- From: "Martin Miko" <[email protected]> To: [email protected] Sent: Friday, June 7, 2013 9:04:46 AM Subject: Re: newbie question on using column itemRenderer in AdvancedDataGrid Good to hear you found the problem. I wanted to ask, if the provider itself has some data, but I thought you ruled this out already. One way or another, here are some tips, that might save you some frustration: 1) Unless you really want to have something else rendered as the default label in the column, don't use a custom renderer. Use what I sent instead. Less flexible, but much less complicated. 2) If you use a renderer, always remember the renderers are reused, i.e. it does not work in a way that each cell has it's own renderer. There's a bunch of them created when the view is rendered and they are reused when you scroll. 3) When you have a custom renderer, and you want to make it editable, you will have to put some effort and sometimes even creativity into it. :) On Fri, Jun 7, 2013 at 5:51 PM, <[email protected]> wrote: > Hi Martin, > > The links look great, thanks for including them. > > I figured out my problem -- I only populate the data provider after > creation complete, so when the mxml initially runs, there's no data > available. The app needs to do some work first before it's created. > Therefore, I changed the item renderer as follows: > > override public function validateProperties():void { > super.validateProperties(); > if (data!=null) // I added this line of code > text=formatFn(data); > } > > Now, the app starts without complaining about finding null values for data > inside formatFn(). > > Thanks so much! > > > ----- Original Message ----- > From: "Martin Miko" <[email protected]> > To: [email protected] > Sent: Friday, June 7, 2013 8:35:32 AM > Subject: Re: newbie question on using column itemRenderer in > AdvancedDataGrid > > Well, if you need only to get a formatted string out of the provided data > object, try using either formatter [1] have a look at the part about *Using > a data formatter in a column*, or labelFunction [2] a for particular > column. The provided example is a bit more on the complex side, but have a > look at label functions and how they are used. > > Otherwise the code seems to be ok, at least the part you posted, but I > might have missed something. > > [1] > http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_04.html > [2] > > http://cookbooks.adobe.com/post_Formatting_summary_data_in_an_Advanced_Datagrid-11471.html > > > On Fri, Jun 7, 2013 at 5:06 PM, <[email protected]> wrote: > > > Hi Experts, > > > > I'm trying to create a Flex 4.5.1 app using an AdvancedDataGrid with a > > column itemRenderer. See the code snippets below for the application and > > item renderer. > > > > The problem I see is when I debug and place a break point inside > > myItemRenderer.mxml located in either of the two places shown below, the > > values for variables "value" and "data" are null. > > > > I'm not trying to do anything unusual here (guessing it should be > textbook > > implementation). > > > > The only info I can find on ADG using item renderers, does not include > > where the columns are defined in mxml: > > > > > http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7bf2.html > > > > So I suspect the column item renderers for ADG behave similar to regular > > mx or spark DataGrid. But don't I have to use an > > mx:AdvancedDataGridItemRenderer when I build the item renderer component? > > > > How do I connect the item renderer to the ADG column so I can format the > > column data using my function: formatMyData()? > > > > Any help to straighten me out would be much appreciated. Thanks in > advance > > for any comments. > > > > > > ----------- CODE SNIPPETS-------------- > > > > ********** Application ********* > > > > <mx:AdvancedDataGrid id="myGrid" ... > > > <mx:columns> > > <mx:AdvancedDataGridColumn id="c0" headerText="" > > dataField="label"/> > > <mx:AdvancedDataGridColumn id="c1" dataField="Name" > > itemRenderer="com.mycompany.myItemRenderer"/> > > </mx:columns> > > ... data provider and other stuff not shown here... > > </mx:AdvancedDataGrid> > > > > > > ********* myItemRenderer.mxml ********* > > > > <mx:AdvancedDataGridItemRenderer > > xmlns:fx="http://ns.adobe.com/mxml/2009" > > xmlns:s="library://ns.adobe.com/flex/spark" > > xmlns:mx="library://ns.adobe.com/flex/mx"> > > > > <fx:Script> > > <![CDATA[ > > > > import mx.controls.AdvancedDataGrid; > > > > override public function set data(value:Object):void { > > super.data=value; // BREAKPOINT 1, where I see value=null > > } > > > > override public function validateProperties():void { > > super.validateProperties(); > > text=formatFn(data); // BREAKPOINT 2, where I see data=null > > } > > > > private function formatMyData(data:Object):String { > > var returnedData:String; > > ... do various formatting here ... > > return returnedData; > > } > > > > ]]> > > </fx:Script> > > </mx:AdvancedDataGridItemRenderer> > > > > > > -- > Martin Miko > -- Martin Miko
