Kevin,

As long as the function reference is passed in through your column
object, you should be able to set it like you have already.

Here's an example using your creation method for the datagrid column:


<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";
                                initialize="initPage()">


<mx:DataGrid id="myDG" width="100%" height="200" />


<mx:Array id="dgArray">

        <mx:Object firstname="Brendan" lastname="Meutzner" age="25"
occupation="Flex/Flash Developer" />
        <mx:Object firstname="Clint" lastname="Modien" age="27"
occupation="Flex Developer/Architect" />
        <mx:Object firstname="Ben" lastname="Luckyk" age="28"
occupation="Flex/Java Developer" />

</mx:Array>

<mx:Script>

        <![CDATA[

        
        import mx.controls.gridclasses.DataGridColumn;
        
        private function initPage():Void
        {
        
                myDG.addColumn(createDataGridColumn({columnName:"name",
headerText:"Name", labelFunction:this["setName"], width:150}));
                myDG.addColumn(createDataGridColumn({columnName:"age",
headerText:"Age", width:50}));
                myDG.addColumn(createDataGridColumn({columnName:"occupation",
headerText:"Occupation"}));
                myDG.dataProvider = dgArray;
        }
        
        function createDataGridColumn(columnProps:Object):DataGridColumn
        {
                var _dgc:DataGridColumn = new 
DataGridColumn(columnProps.columnName);
                _dgc.headerText = columnProps.headerText;
                if(columnProps.width)
                {
                        _dgc.width = columnProps.width;
                }
                if(columnProps.labelFunction)
                {
                        _dgc.labelFunction = columnProps.labelFunction;
                }
                return _dgc;
        }
        
        function setName(row:Object):String
        {
                return row.lastname + ", " + row.firstname;
        }
        
        ]]>

</mx:Script>


</mx:Application>


Brendan

--- In flexcoders@yahoogroups.com, "Kevin Ewok" <[EMAIL PROTECTED]> wrote:
>
> Brendan-
>   Thanks for your response. That makes sense but I'm still in the dark
> about how to assign a Function to the 'labelFunc' attribute
> dynamically when I create the Datagrid. All I will have is the name of
> the function, such as "displaySpecificText", so where is the method
> actually implemented?? Like in your code, for "return
> column.labelFunction(item);" ...where is that set?
> 
> Thanks again!
> 
> --- In flexcoders@yahoogroups.com, "Brendan Meutzner" <[EMAIL PROTECTED]>
> wrote:
> >
> > Hey Kevin,
> > 
> > If I understand correctly, how would this work...
> > 
> > //CellrendererClass.as/mxml
> > 
> > public var listOwner:DataGrid;
> > public var getCellIndex:Function;
> > public var item:Object;
> > public function setValue(str:String, item:Object, sel:String):Void 
> > {
> > var position:Object = getCellIndex();
> > var column:DataGridColumn =
> > DataGridColumn(listOwner.getColumnAt(position.columnIndex));
> >             
> > if(column.labelFunction != null)
> > {
> > return column.labelFunction(item);
> > }
> > this.item = item;
> > }
> > 
> > 
> > By obtaining a reference for the current column within the
> > cellrenderer, you can call the labelFunction within the setValue
method.
> > 
> > Does this help?
> > 
> > 
> > Brendan
> > 
> > 
> > 
> > --- In flexcoders@yahoogroups.com, "Kevin Ewok" <[EMAIL PROTECTED]>
wrote:
> > >
> > > Hello all.
> > >  
> > > I have a form where a user enters criteria and chooses from a
list box
> > > the columns they want to see in their search results (in the
form of a
> > > datagrid). The List of columns is linked to <mx:model> in a XML
file.
> > > 
> > > I am able to generate the datagrid successfully along with cell
> > > renderers, but I am not sure how to dynamically add a
"labelFunc" b/c
> > > there are several columns where I need to process the value before
> > > displaying.
> > > 
> > > My code looks like this:
> > > 
> > > // Code to create Datagrid
> > > // Loop through the 'column' objects defined in my xml Model and 
> > > //   call createDataGridColumn method.
> > > 
> > > /* create column */
> > > function createDataGridColumn(column : Object) : DataGridColumn 
> > >  {
> > >   var _dgc:DataGridColumn = new DataGridColumn(column.name);
> > >   _dgc.headerText = column.headerText;
> > >   _dgc.width = column.width;      
> > >   if(column.labelFunction != undefined)
> > >   {       
> > >           _dgc.labelFunction = column.labelFunction;
> > >           //_dgc.labelFunction = "displayText";
> > > 
> > >   }
> > >   return _dgc;
> > > }
> > > 
> > > THE QUESTION OF THE HOUR is that the _dgc.labelFunction line within
> > > the if statement is assigned the text of the method name, for
example,
> > >  in the commented line below. So where do I place the implementation
> > > of this method???
> > > 
> > > The following attempts by me didn't work:
> > > 1.) I tried extending the DataGridColumn class and implementing the
> > > method there. 
> > > 2.) Implement the method in the class of the code above.
> > > 3.) Implement the method in the calling class of the code above.
> > > 
> > > Thanks in advance for any help!
> > > 3.
> > >
> >
>







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to