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()
                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);


      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%"
       <mx:DataGridColumn headerText="Nombre de evento" width="150"
       <mx:DataGridColumn headerText="ID" width="40"
       <mx:DataGridColumn headerText="Propietario" width="120"
       <mx:DataGridColumn headerText="Fecha" width="70"
       <mx:DataGridColumn headerText="Hora" width="55"
       <!-- <mx:DataGridColumn headerText="N. Parámetros" width="100"
       dataField="numParams"/> -->
       <mx:DataGridColumn headerText="Parámetros"
       <mx:DataGridColumn headerText="Archivo" width="40"


      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.




      PD: sorry for my english