1 Reply Latest reply on Jul 29, 2009 11:37 PM by Flex harUI

    Enabled/Disabled color row Datagrid

    lerooooogk Level 1

      Hi all,

       

      I extend class Datagrid to draw rows depending a value.

      package comp
      {
           import flash.display.Sprite;
           
           import mx.controls.DataGrid;
           import mx.core.Application;
      
           public class DataGridEx extends DataGrid
           {
                public var rowColorFunction:Function;
                
                public function DataGridEx()
                {
                     super();
                }
                
                override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void
                {
                     if ( rowColorFunction != null && dataProvider != null ){
                          var item:Object;
                          if (dataIndex < dataProvider.length){
                               item = dataProvider[dataIndex];               
                          }
                          if (item){
                               color = rowColorFunction(item,rowIndex,dataIndex,color);
                          }
                     }
                     super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);
                }
           }
      }
      

       

      In MXML i wrote this. My purpose is user could chosse if the rows are coloured or not.

       

                private function colorRow():void{               
                     if (colorRowByFile == false){
                          colorRowByFile = true;                    
                     }
                     if (colorRowByFile == true){
                          colorRowByFile = false;
                     }          
                }
      

       

      And finally the code of Datagrid and color:

       

      public function calcRowColor(item:Object, rowIndex:int, dataIndex:int, color:uint):uint
                 {
                       if(item.numFile == 1)
                          return 0x49FFAD;
                     if(item.numFile == 2)
                          return 0x33CCFF;
                     if(item.numFile == 3)
                          return 0xFFCC66;
                     if(item.numFile == 4)
                          return 0xFFFF99;
                     if(item.numFile == 5)
                          return 0xFF6633;
                     if(item.numFile == 6)
                          return 0xFFCCCC;
                     if(item.numFile == 7)
                          return 0x996600;
                     if(item.numFile == 8)
                          return 0xCCFF99;     
                     else return 0xFFFFFF;             
                 }
      
      
      
      <comp:DataGridEx id="dg_events" width="100%" height="100%"
       dataProvider="{eventList.eventCollection}"
       rowColorFunction="calcRowColor">
       <comp:columns>
       <mx:DataGridColumn headerText="Nombre de evento" width="150"
       dataField="name"/>
       <mx:DataGridColumn headerText="ID" width="40"
       dataField="eventId"/>
       <mx:DataGridColumn headerText="Propietario" width="120"
       dataField="owner"/>
       <mx:DataGridColumn headerText="Fecha" width="70"
       dataField="date"/>
       <mx:DataGridColumn headerText="Hora" width="55"
       dataField="time"/>
       <!-- <mx:DataGridColumn headerText="N. Parámetros" width="100"
       dataField="numParams"/> -->
       <mx:DataGridColumn headerText="Parámetros"
       labelFunction="eventList.getParams"/>
       <mx:DataGridColumn headerText="Archivo" width="40"
       dataField="numFile"/>
       </comp:columns>
       </comp:DataGridEx>
      

       

      The problem is:

       

      Initially the option are enabled so the rows are correctly coloured depending the value of column numFile. When user clicks to disabled colors, datagrid appears correct (with no color) but if we click again to recoloured row the datagrid still the same state (with no colour).

       

      I dont know the reason.

       

      Thanks in advanced.

       

      Lerogke

       

      PD: sorry for my english