flex实现DataGrid高亮显示数据功能的解决方案(flex两端对齐怎么设置)全程干货

随心笔谈3个月前发布 admin
197 00
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

文章摘要

本文介绍了一个名为`SpecialDataGrid`的自定义数据网格类,继承自`mx.controls.DataGrid`。该类提供了以下功能: 1. 定义了`_rowColorFunction`私有变量,用于通过外部方法设置行的背景颜色。2. 实现了`setRowColorFunction`和`getRowColorFunction`方法,分别用于设置和获取行颜色函数。3. 重写了`drawRowBackground`方法,通过调用自定义的颜色函数(如果存在)动态设置行背景颜色,并基于数据项进行调整。4. 该类通过继承和自定义方法,增强了数据网格的灵活性,允许根据需要动态调整行的样式。 总结:该文章重点介绍了通过自定义方法实现数据网格行背景颜色的动态设置功能。

package org.lxh 

{    

    import flash.display.Sprite; 

    import mx.controls.DataGrid; 

    public class SpecialDataGrid extends DataGrid 

    { 

        private var _rowColorFunction:Function;   //用于在外部能通过指定一个方法 去实现改变列的背景色 

        public function SpecialDataGrid() 

        { 

            super(); 

        } 

        public function set rowColorFunction(f:Function):void 

        { 

            this._rowColorFunction=f; 

        } 

        public function get rowColorFunction():Function 

        { 

            return this._rowColorFunction; 

        } 

        //复写该方法 

        override protected function drawRowBackground(s:Sprite,rowIndex:int,y:Number, height:Number, color:uint, dataIndex:int):void 

        { 

            if( this.rowColorFunction !=null ){ 

                if( dataIndex < this.dataProvider.length ){ 

                    var item:Object=this.dataProvider.getItemAt(dataIndex); 

                    color=this.rowColorFunction.call(this, item, color); 

                } 

            }            

            super.drawRowBackground(s, rowIndex, y, height, color, dataIndex); 

        } 

    } 

}

© 版权声明

相关文章