Connecting Tech Pros Worldwide Help | Site Map

Flex, Datagrids, rows & how to expand a row

Newbie
 
Join Date: May 2008
Posts: 16
#1: Oct 17 '08
Hi Everyone,

It's been a long time and I'm always appreciative of your help.

I'm working on a Datagrid at the component level in Flex.

I know that I can expand a row within the Datagrid by clicking on a row:

Expand|Select|Wrap|Line Numbers
  1.         private function onItemClick(e : ListEvent) : void
  2.         {
  3.             // setting these xml properties will automatically update the itemRenderers on the fly
  4.  
  5.             // expand the item clicked on
  6.             var selData : AssetInfo = e.itemRenderer.data as AssetInfo;
  7.             if (selData.expanded != true)
  8.                 selData.expanded = true;
  9.                }
  10.  
But when I try to accomplish the same thing with a mouse rollover, then I can no longer access ListEvent. Probably because rollOver has to deal with MouseEvent.

Nevertheless, I am able to see what the mouse is rolling over by way of trace:

Expand|Select|Wrap|Line Numbers
  1. I use the datagrid's property of rollOver="onCreationComplete()" to call the addEventListener
  2.  
  3.         private function onCreationComplete():void
  4.         {
  5.             //register for the mouse_over enter event
  6.             var myListener = addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);        
  7.         }
  8.  
  9.         private function onMouseOver(myListener):void
  10.         {
  11.             trace(myListener);
  12.         }
  13.  
  14.  
The question is, what can I do with the information being shown by the trace to expand one of the rows, as I do when I click on one of the rows.

Here's what is returned in the trace
Expand|Select|Wrap|Line Numbers
  1. [MouseEvent type="mouseOver" bubbles=true cancelable=false eventPhase=3 localX=12 localY=91 stageX=999 stageY=270 relatedObject=MyAppAir0.$MyApp.Shell114.HDividedBox115.$browser.$am.$tabnav.Canvas371.$assetList.ListBaseContentHolder376.DataGridItemRenderer1733 ctrlKey=false altKey=false shiftKey=false buttonDown=false delta=0 commandKey=false controlKey=false clickCount=0]
  2.  
  3.  
Thanx n advance
Newbie
 
Join Date: May 2008
Posts: 16
#2: Oct 20 '08

re: Flex, Datagrids, rows & how to expand a row


I figured it out.

It was an epic “programming” journey over the weekend for me to figure out how to do the rollover on the items within the datagrid.

First, I found out that this lib(flexlib:VAccordion) cannot be used with Flex Builder 2, which is what I have at home. Then I found out that Flex Builder 3 can only run with Java 1.5, which is the version of Java that is allowed to install on 10.5 OS, which I am running 10.4. After that, I found out that the flexlib:VAccordion from the open source google code could not be implemented at the component level, which had me starting over from scratch. So, after battling with myself on how long it would take for me to get fired, I had to figure out that I had to use a listEvent, rather than a MouseEvent.

This morning, I discovered in an adobe tech manual, that itemRollOver, as opposed to RollOver, uses the ListEvent and not the MouseEvent. From there I was able to determine the rowIndex and the rest is datagrid history.

Expand|Select|Wrap|Line Numbers
  1. first, use the itemRollOver within the datagrid header
  2. <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml" 
  3.     width="100%" height="100%" 
  4.     verticalScrollPolicy="on"
  5.     paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0"
  6.     itemClick="onItemClick(event)"
  7.     variableRowHeight="true"
  8.     borderThickness="0"
  9.     showHeaders="false"
  10.     verticalGridLines="false" 
  11.     selectionColor="#EEEEEE"
  12.     rollOverColor="#D3D8DE"
  13.     textRollOverColor="#FFFFFF"
  14.     textSelectedColor="#000000"
  15.     color="#FFFFFF" 
  16.     styleName="listView"
  17.     itemRollOver="onMouseOver(event)"
  18. >
  19.  
  20. Then use this function to expand each row that the mouse rolls over:
  21.  
  22. import mx.events.DataGridEvent;
  23.  
  24. private function onMouseOver(event:ListEvent):void
  25. {
  26.     var myRow = event.rowIndex;
  27.     var data2 : ArrayCollection = this.dataProvider as ArrayCollection;
  28.  
  29.         for(var i:int = 0; i < data2.length; i++)
  30.         {
  31.             var dat2 : AssetInfo = data2[i] as AssetInfo;
  32.  
  33.             if (dat2 != data2[myRow] && dat2.expanded != false)
  34.                 dat2.expanded = false;
  35.         }
  36.         data2[myRow].expanded = true;
  37.         //trace(myRow);
  38. }
  39.  

And that's all there is to it :-)
Newbie
 
Join Date: May 2008
Posts: 16
#3: Dec 15 '08

re: Flex, Datagrids, rows & how to expand a row


Left something out that is pretty important to making this work:

expand is a state:
Expand|Select|Wrap|Line Numbers
  1.     <mx:states>
  2.         <mx:State name="expanded">
  3.             <!-- <mx:SetProperty name="height" value="196"/> -->
  4.             <mx:AddChild position="lastChild">
  5.  
  6.                 <mx:Canvas x="10" y="33" width="100%" height="100%" backgroundColor="#000000" id="$thumb" click="showPreview();" />
  7.  
  8.             </mx:AddChild>
  9.         </mx:State>
  10.     </mx:states>
  11.  
Also, this comes from an itemrenderer in the first column of the datagrid.

Expand|Select|Wrap|Line Numbers
  1. <mx:DataGridColumn id="assetDGC" itemRenderer="FirstColumn" headerText="Name" width="575" minWidth="160" sortable="true" sortCompareFunction="sortByName" />
  2.  
Newbie
 
Join Date: Jul 2009
Posts: 1
#4: Jul 16 '09

re: Flex, Datagrids, rows & how to expand a row


Kronus,
Is AssetInfo a separate class that has a member variable named expanded? How does the switching of the state occur? What does the itemrenderer for the datagrid column look like? Just a few questions after seeing this thread. Thanks for your reply in advance.

Thanks.
Reply