Search code examples
flex3advanceddatagriddataproviderhierarchicaldisclosure

AdvancedDataGrid Problem (Bug?) -- Disclosure Icons in Wrong Column. (Hierarchical data, Flex 3.5)


I've run into a bit of a funny one and thought it was worth posting:

I'm using an Advanced Data Grid in a case where I've got to set the data provider at runtime using hierarchical data. The adobe docs don't really cover this kind of thing (at least not at the level I could dig to).

Has anyone run into this before?

The only thing I could come up with was a bit hackish and seems to introduce some strange behavior with the disclosure icons of the advanced grid. I've included a test case below:

advancedDataGridProblem.as:

 import mx.collections.ArrayCollection;

 public var dataProvider:ArrayCollection = new ArrayCollection([{label:"item1"},
             {label:"item2", children:[{label:"subItem1"},{label:"subItem2"},
             {label:"subItem3"}]},
             {label:"item3"}]);

 public function init():void{
      //using callLater to ensure that the grid has been created before setting DP
      this.callLater(setDataProvider,[dataProvider]);
 }

 public function setDataProvider(list:ArrayCollection):void{
      heirData.source = list;
 }

and the mxml:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
     <mx:Script source="advancedDataGridProblem.as"/>


  <mx:AdvancedDataGrid id="advDG" width="100%">

   <mx:columns>
        <mx:AdvancedDataGridColumn headerText="What the heck?"/>
        <mx:AdvancedDataGridColumn headerText="Label" dataField="label"/>
        <mx:AdvancedDataGridColumn headerText="Column 2"/>
        <mx:AdvancedDataGridColumn headerText="Column 3"/>
   </mx:columns>

   <mx:dataProvider>
        <mx:HierarchicalData id="heirData"/>
   </mx:dataProvider>
 </mx:AdvancedDataGrid>

</mx:Application>

As you can see when you run the test application, the icons which should show up in the Label column are actually placed in the "What the heck?" column. If you drag the Label column over and attempt to swap it with the "What the heck?" column, the icons remain where they are, but miraculously, the labels that were previously left aligned for the Label column are now formatted appropriately for the icons. Dragging the Label column out of slot one will revert the grid to it's original condition.

This one's a little above my head - anyone have any suggestions?

Ideally, I'd like to get around this hack all together and just assign the dataProvider as per usual at run-time.

Thanks in advance!

I'll be filing a bug report with adobe about this one shortly, and will throw the link into a comment.


Solution

  • To resolve the disclosure icon issue noted above, you can specify the AdvancedDataGrid's "treeColumn" property, passing the id of the column which your tree data should be in.

    Apparently I was blind the other day looking at the livedocs.

    Cheers!