Thursday, October 23, 2008

Icon on Grouped Column of Advanced Data Grid


In Flex, On a GroupingCollection as a DataProvider to my AdvancedDataGrid, i wanted to have an icon (itemRenderer) only on the leaf nodes of my AdvancedDataGrid (grouped data). This is how my initial code was: -> Script block of my ActionScript->
   import mx.collections.ArrayCollection;
   
   [Bindable]
   private var collection:ArrayCollection = new ArrayCollection([{group:'group1', id:'1', name:'name1'}, 
                    {group:'group1', id:'2', name:'name2'}, 
                    {group:'group2', id:'3', name:'name3'}]);
   private function setDP():void
   {
    gc.refresh();
    adg.expandAll();
   }



 
  
 

 
  
   
    
     
      
     
    
   
  
  
   
   

      
       
        
         
          
         
        
       
       
  
 





And my surprising output was -
I then removed inline item renderer and used external renderer (thanks to Srinivas Annam).


 
  private var obj:Object;
  
  override public function set data(value:Object):void
  {
   super.data=value;
   obj=value;
   apply(value);
  }
  
  private function apply(data:Object):void
  {
   if(data == null)
    return;
   
   img.source="";
   if(data.name)
   {
    img.source="assets/test.png";
   }
  }
  
 

And I added the itemrederer for the column as :


And I got the output i wanted:

0 comments: