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