Well, I found you can simply pass a Function object to the custom DataGridCell and have the custom cell handle its own click method with that Function. The drawback is that the function must live in the same MXML file that the DataGridCell is declared in. I'd still much rather use Flex's own event handling mechanisms. Any other ideas? Have I stumped the flexcoders?!
--- In [email protected], "mrmcfeely8" <[EMAIL PROTECTED]> wrote: > Hi all, > > I'm trying to create an easy way to apply a custom cell renderer to a > DataGridColumn *and* keep that cell renderer flexible enough so that > its behavior can be configured from the mxml file that contains the > DataGridColumn. > > For example, I have a LinkCellRenderer that displays a column's text > as a link. However, I'd like to reuse that renderer throughout my > application, using different handlers for the link's "click" event. > Ideally, I'd like to do something like this: > > <mx:DataGrid ... > > <mx:columns> > <mx:Array> > <mx:DataGridColumn columnName="textField1" /> > <mx:DataGridColumn columnName="textField2" /> > <custom:DataGridLinkColumn columnName="linkField" > click="myLocalClickHandler(event)" /> > </mx:Array> > </mx:columns> > </mx:DataGrid> > > I've tried implementing this by creating a class called > DataGridLinkColumn that extends > mx.controls.gridclasses.DataGridColumn. It looks something like this: > > // BEGIN CODE > import mx.events.*; > > [Event("click")] > class DataGridLinkColumn extends mx.controls.gridc > lasses.DataGridColumn { > public function clickPropagator(event) { > var eventObj:Object = new Object(); > eventObj.type = "click"; > eventObj.item = event.item; > dispatcher.dispatchEvent(eventObj); > } > > public function DataGridLinkColumn() { > cellRenderer = LinkCellRenderer; > } > > private static function staticConstructor():Boolean { > EventDispatcher.initialize(dispatcher); > return true; > } > > private static var staticConstructed:Boolean = staticConstructor(); > public var addEventListener:Function; > public var removeEventListener:Function; > private static var dispatcher:Object = new Object(); > } > // END CODE > > LinkCellRenderer is your basic custom cell renderer (in this case, > rendering a link). It uses the DataGridLinkColumn's "clickPropagator" > method to handle the link's "click" method. "clickPropagator" would > then emit a "click" event from the DataGridLinkColumn. This would > allow you to define a "click" handler right from the mxml file that > has the DataGridColumn declarations... like the first code sample. > > The problem is, while Flex tries to compile those classes, I get the > king of all exceptions, "java.lang.NullPointerException". That > exception seems to go away when I remove the "Event" metadata tag from > the DataGridLinkColumn class, but that tag's obviously needed for that > method to emit a "click" event. > > Anyone have any ideas? Is there a better way to go about this? > > -Doug -- 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/

