And that works irregularly as well. I ended up putting in a half second timer 
to pop and then reinsert an item from each arrayCollection. Something just 
isn't happening in the various pieces of logic that marry up what's displayed 
with what the data is. The way this is trending, I might even be stripping out 
other events. That's good for code simplicity but ridiculous that I have to use 
a timer to fix a FLEX bug.

--- In flexcoders@yahoogroups.com, "atomilux" <atomi...@...> wrote:
>
> Not sure what that means ...
> 
> Well, until I find something better - my deadline is fast approaching and I 
> don't have time to wait so I figured out a hack. It involves 2 event 
> listeners and "jolting" the dataProvider to simulate a manual reordering 
> (which triggers the right resizing btw). Also, I need DataGrid reordering to 
> NOT short circuit so it detects if you're reordering vs shuffling data from 
> one DG to the other.
> 
> Code:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute" 
> creationComplete="init()">
>       <mx:Script>
>               <![CDATA[
>                       import mx.events.DragEvent;
>                       import mx.events.CollectionEvent;
>                       
>                       import mx.collections.ArrayCollection;
>                                               
>                       public var derXML:XML = <root> 
>                                                               <category 
> order="0" x="0" y="0" width="200" height="200">
>                                                                       
> <name>Category 1</name>
>                                                                       <item 
> order="0">
>                                                                               
> <text>Some item number 1 in cat 1</text>
>                                                                       </item>
>                                                                       <item 
> order="1">
>                                                                               
> <text>Some item number 2 in cat 1</text>
>                                                                       </item>
>                                                                       <item 
> order="2">
>                                                                               
> <text>Some item number 3 in cat 1</text>
>                                                                       </item>
>                                                                       <item 
> order="3">
>                                                                               
> <text>Some item number 4 in cat 1</text>
>                                                                       </item>
>                                                                       <item 
> order="4">
>                                                                               
> <text>Some item number 5 in cat 1</text>
>                                                                       </item>
>                                                               </category>
>                                                       </root> ;
>                                                       
>                       public var derXML2:XML = <root> 
>                                                               <category 
> order="0" x="0" y="0" width="200" height="200">
>                                                                       
> <name>Category 2</name>
>                                                                       <item 
> order="0">
>                                                                               
> <text>Some item number 1 in cat 2</text>
>                                                                       </item>
>                                                                       <item 
> order="1">
>                                                                               
> <text>Some item number 2 in cat 2</text>
>                                                                       </item>
>                                                                       <item 
> order="2">
>                                                                               
> <text>Some item number 3 in cat 2</text>
>                                                                       </item>
>                                                                       <item 
> order="3">
>                                                                               
> <text>Some item number 4 in cat 2</text>
>                                                                       </item>
>                                                                       <item 
> order="4">
>                                                                               
> <text>Some item number 5 in cat 2</text>
>                                                                       </item>
>                                                               </category>
>                                                       </root> ;               
>                                         
>                       
>                       [Bindable] var derData:ArrayCollection;
>                       [Bindable] var derData2:ArrayCollection;
>                       private var sourceDG:DataGrid;
>                       
>                       
>                       public function init():void {
> 
>                               buildMXMLfromXML();
>                       
>                       }//end func
>                       
>                       public function buildMXMLfromXML():void {
>                                                                               
>                 
>                               var categoriesXML:XML = derXML.category.(@order 
> == 0)[0];
>                               var categoriesXML2:XML = 
> derXML2.category.(@order == 0)[0];
> 
>                               //get the items for this category
>                               var itemList:XMLList = categoriesXML.item;
>                               var itemList2:XMLList = categoriesXML2.item;
>                               
>                               derData = new ArrayCollection();
>                               derData2 = new ArrayCollection();
>                               
>                               for (var j:uint=0;j<itemList.length();j++) {
>                                       
> derData.addItem({item:itemList[j].text.toString()});
>                               }//end for
>                               
>                               for (var j:uint=0;j<itemList2.length();j++) {
>                                       
> derData2.addItem({item:itemList2[j].text.toString()});
>                               }//end for
>                               
>                               mainDataGrid.dataProvider = derData;
>                               mainDataGrid2.dataProvider = derData2;
>                               
>                       }//end function buildMXMLfromXML()
>                       
>                       
>                       public function valueCommitHandler(evt:Event):void {
>                               
>                               var tmpDG:DataGrid = evt.currentTarget as 
> DataGrid;
>                               joltDataProvider(tmpDG);
>                               resizeDG(tmpDG);
>                                                               
>                       }//end function
>                       
>                       
>                       public function dragDropHandler(evt:DragEvent):void {
>                               
>                               var tmpDG:DataGrid = evt.currentTarget as 
> DataGrid;
>                               
>                               //reordering gets short circuited if we don't 
> do this
>                               if (sourceDG != tmpDG) {
>                                       joltDataProvider(tmpDG);
>                               }
>                               
>                               resizeDG(tmpDG);
>                               
>                       }//end function
>                       
>                       public function resizeDG(dg:DataGrid):void {
>                               
>                               var measureHeight:Number = 
> dg.measureHeightOfItems(-1,dg.dataProvider.length);
>                               
>                               if (measureHeight > 10) {
>                                       dg.height = dg.viewMetrics.top + 
> measureHeight + dg.viewMetrics.bottom;
>                               }//end if
>                               
>                       }//end function
>                       
>                       //This trigger something in the DataGrid for a re-render
>                       public function joltDataProvider(dg:DataGrid):void {
>                               
>                               //in case the user just emptied the 
> DG.dataProvider
>                               if (dg.dataProvider.length > 0) {
>                                       var tmpItm = 
> dg.dataProvider.removeItemAt(0);
>                                       dg.dataProvider.addItemAt(tmpItm,0);
>                               }
>                               
>                       }//end function
>                       
>                       public function registerSourceDG(evt:Event):void {
>                               
>                               sourceDG = evt.currentTarget as DataGrid;
>                               
>                       }//end function
>                       
>                       
>               ]]>
>       </mx:Script>
>       <mx:VBox width="800">
>               <mx:Box id="category1" width="100%">
>               
>                       <mx:DataGrid id="mainDataGrid" 
>                                               dragEnabled="true" 
>                                               dropEnabled="true" 
>                                               dragMoveEnabled="true" 
>                                               editable="false"
>                                               allowDragSelection="true"
>                                               verticalScrollPolicy="off"
>                                               variableRowHeight="true"
>                                               
> valueCommit="{valueCommitHandler(event)}"
>                                               
> dragDrop="{dragDropHandler(event)}"
>                                               
> dragStart="{registerSourceDG(event)}"
>                                               
>                                               width="100%" 
>                                               showHeaders="false"
>                                               alternatingItemColors="#FFFFFF"
>                                               borderThickness="0"
>                                               verticalGridLines="false"
>                                               rollOverColor="#AAA9A9">
>                               <mx:columns>
>                                       
>                                       <!-- Text -->
>                                       <mx:DataGridColumn dataField="item" 
> paddingLeft="5" wordWrap="true"/>
>                                       
>                               </mx:columns>
>                       </mx:DataGrid>
>                       
>               </mx:Box><!-- end category 1 -->
>               
>               <mx:Box id="category2" width="100%">
>                       
>                       <mx:DataGrid id="mainDataGrid2" 
>                                               dragEnabled="true" 
>                                               dropEnabled="true" 
>                                               dragMoveEnabled="true" 
>                                               editable="false"
>                                               allowDragSelection="true"
>                                               verticalScrollPolicy="off"
>                                               variableRowHeight="true"
>                                               
> valueCommit="{valueCommitHandler(event)}"
>                                               
> dragDrop="{dragDropHandler(event)}"
>                                               
> dragStart="{registerSourceDG(event)}"
>                                               
>                                               width="100%" 
>                                               showHeaders="false"
>                                               alternatingItemColors="#FFFFFF"
>                                               borderThickness="0"
>                                               verticalGridLines="false"
>                                               rollOverColor="#AAA9A9">
>                               <mx:columns>
>                                               
>                                       <!-- Text -->
>                                       <mx:DataGridColumn dataField="item" 
> paddingLeft="5" wordWrap="true"/>
>                                       
>                               </mx:columns>
>                       </mx:DataGrid>
>               </mx:Box><!-- end category 2 -->
>                       
>       </mx:VBox>
>       
> </mx:Application>
> 
> 
> 
> --- In flexcoders@yahoogroups.com, Alex Harui <aharui@> wrote:
> >
> > You might get more than on e updateComplete.
> > 
> > 
> > On 3/18/10 9:30 AM, "atomilux" <atomilux@> wrote:
> > 
> > 
> > 
> > 
> > 
> > 
> > updateComplete failed because the dataProvider came back as null.
> > 
> > viewMetrics added back in.
> > 
> > --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , 
> > Alex Harui <aharui@> wrote:
> > >
> > > ValueCommit probably isn't the right event.  The DG probably doesn't have 
> > > the final width yet so the heights will not calculate correctly.  Maybe 
> > > try updateComplete.  Also, you are not factoring in 
> > > viewMetrics.top/bottom.
> > >
> > >
> > > On 3/16/10 8:08 AM, "atomilux" <atomilux@> wrote:
> > >
> > >
> > 
> > 
> > 
> > 
> > 
> > 
> > --
> > Alex Harui
> > Flex SDK Team
> > Adobe System, Inc.
> > http://blogs.adobe.com/aharui
> >
>


Reply via email to