Posted by: Stephen Gray on: 6 August, 2008
I’ve just had a thought that it was hard to come accross resources for handling double click events on DataGrids in Flex 3.
There are lots of tutorials on how to handle them in Flex 2 but this doesn’t apply for Flex 3, as Flex 3 natively handles double click events and Flex 2 did not.
There are also a lot of tutorials on how to amend functionality so that you have to double click to edit a row instead of the default single click. This tutorial does not cover this, this tutorial covers functionality of double clicking a row and then triggering something. I.E. a table of products, you want to double click a row to view product details etc.
First off, we need to make a slight amendment to our DataGrid (or AdvancedDataGrid, same applies to both):
<mx:DataGrid id="MyDataGrid" doubleClickEnabled="true" itemDoubleClick="functionName(event);">
...
There are obvious meanings to both of these new attributes; doubleClickEnabled is used to tell Flex we want to allow/handle double click events on this DataGrid and itemDoubleClick tells Flex which function to use.
The above function should look something like:
protected function functionName(event:ListEvent):void
{
var selectedRow:Object = event.currentTarget.selectedItem;
Alert.show(selectedRow.myVariableName);
}
You can directly access the selected row from the DataGrid using the event.currentTarget.selectedItem reference. You can then access any variable that exists in the DataGrid’s dataProvider for that row.
Of course to get the above working you’ll need to:
import mx.controls.Alert;
import mx.events.ListEvent;
Stephen.
I need to work with the column name rather than the field name as this is a column in the DataGrid that is modified if the row has been clicked on.
Actually to be more clear, I need to change the image in the column if the row is clicked on. I have tried an ItemRenderer both inline as a Component and external; but I am still not able to modify the image in the column.
Sorry, to be even more clear, I need to change the image in a particular cell of the row that was double clicked on, not the entire column.
The issue is that you don’t necessarily click on the column containing the image. If you click anywhere in the row, you make the image invisible which is simpler than swapping out images.
Editing a string representation of the source would let you swap out the image which would also be ok.
Thanks for feedback!
I gave up on swapping the image for one row and created an inline ItemRenderer with “visible=true”. Now if I change the Boolean value it is bound to upon a click in the row, the image for all rows is set to invisible which is still not what I want!
I had studied that example; but I think what I’m trying to do is not the same. Both columns in that example are from the data provider. My first column, an image column, is one I populate with an inline ItemRenderer->Component->Image tag sequence. The image is set to visible initially, and I need to set it to invisible when the user clicks on the row. I can handle columns from the data provider; but access to this first image populated column escapes me. Thanks for the time you have spent on this.
Thank you soooo much worked fine obviously. but difficult ressource to find although completely straight forward. cheers
Hi ,
Please clarify me.
Requirement: Need to use a itemrenderer link button for a particular column say(ProjectName) in a datagrid. when i click the projectName, need to load a page with its corresponding projectname and its relevant details.
Issue:
i need to get a selected row/ cell value for a column say ProjectName and it has to be appended in the url.
dont know how to retrieve the selected row/cell value by using a datagrid itemrenderer.
kindly help me out to solve this issue .
Great example, any advise how I can hide the row that I doubleclick ?
Hi stephen,
I have a datagrid with 4 columns in which lastcolumn holds itemrenderer as mx:image. am populating the datagrid values from a backend. based on a boolean condition i want to display the image in last column . say if false na, icon should be present in that row. if the value is false that cell shoul not possess any icon.
i dont know how to do this.
as the item renderer is defined for the last datagrid column am getting the icon for all the rows.
please help me out to solve this issue..
Thanks in advance,
nithya
Thanx for the tip
can we use states and transitions in datagrid for swaping columns.i dont know how to do this.if anybody knows please send the code asap.
thank you
Thanks for the help.
30 August, 2008 at 3:46 am
After accessing the row, how does one actually access a particular cell?