I have two files here. 1) MyFavorites 2)
I have a datagrid with an item renderer. The item renderer is
essentially a delete image. I am trying to write a function so when
the user clicks the image, it will remove the row from the
datagrid. The problem I am having is the item renderer sits in its
own file and the DataGrid is in another.
Do I write a private function within the item renderer.mxml
file that will dispatch an event? I think this is only way to do it
as I only want my event dispatched when the user explicitly clicks
So in my itemRenderer I suppose I would write a function
called "deleteRecord()", this function would dispatch an event and
the file which actually contains the DataGrid would listen for the
event and act accordingly. Is this right?
If so, how would I pass a reference to which row I want to
delete? The itemRenderer sits in its own file and seems to not have
any knowledge of my <mx:DataGrid>
My datagrid code is below which shows how I am using my
Your question is a good one and one a lot of people have.
You are correct in your strategy. Have your itemRenderer use
dispatchEvent, but when you create the event, set its bubbles
parameter to true. This will allow the event to climb up the
component chain. You don't need to have the DataGrid listen for
this event; you just need to listen for it in the place where you
want to use it so you can delete the record.
To get the information you want, make sure your itemRenderer
implements IDropInListItemRenderer. Classes which implement this
will have a listData property and that holds the rowIndex. Check
the documentation for this. If your class doesn't have it,
implement it yourself, the documentation shows you how to do this.
Now that you have the information you'll need to dispatch a
custom event which contains the information. Again, check the docs
Finally, you will need to use ActionScript to listen for the
event. Let's say the file in which the DataGrid is declared is the
place where you want to listen for the event. Your custom event
won't be an event the DataGrid normally dispatches, so you can't
use MXML to declare the event listener. Instead, do it in