Avg. Rating 5.0

Problem

A user can select multiple rows of an advanced datagrid. The requirement is to have different back-ground color of the selected rows depending on the value of one of the column attribute.

Solution

The main crux is the item renderer to be used by the datagrid. We can then set color of one of the column or all of the columns of the selected row of datagrid.

Detailed explanation

The main crux is the item renderer to be used by the datagrid. We can then set color of one of the column or al the columns of the selected row of datagrid.
 

package
{
    import flash.display.Graphics;
    import flash.events.Event;
    
    import mx.controls.AdvancedDataGrid;
    import mx.controls.Label;
    import
mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
    import mx.events.ListEvent;

    public class ADGItemrenderer extends Label
    {
        public function ADGItemrenderer()
        {
            addEventListener(ListEvent.ITEM_CLICK,callInvalidate);
        }
       
        public function callInvalidate(event:Event):void{
            invalidateDisplayList();
        }
        override protected function
updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void{
            var g:Graphics = graphics;
           
            super.updateDisplayList(unscaledWidth, unscaledHeight);
            g.clear();
           
            if(super.data){
                    var advancedDataGrid:AdvancedDataGrid =
(listData)?AdvancedDataGrid((listData).owner):null;
                    var column:AdvancedDataGridColumn =
(advancedDataGrid)?advancedDataGrid.columns[listData.columnIndex]
as AdvancedDataGridColumn:null;
                    if(advancedDataGrid.isItemSelected(data)){
                            if(data.severity <300){
                                /*change color accordingly*/
                                g.beginFill(0xCC0033);
                                g.drawRect(0, 0, unscaledWidth,
unscaledHeight);
                                g.endFill();
                            }else if(data.severity <400){
                                /*make it some other color*/
                                g.beginFill(0x00FF00);
                                g.drawRect(0, 0, unscaledWidth,
unscaledHeight);
                                g.endFill();
                            }else{
                                g.beginFill(0x0000FF);
                                g.drawRect(0, 0, unscaledWidth,
unscaledHeight);
                                g.endFill();
                            }
                           
                    }else{
                        return;
                    }
                }
            }
}
}//Package




// Find complete source code in attachment.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes