国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > Flex > 正文

flex實現(xiàn)DataGrid高亮顯示數(shù)據(jù)功能的解決方案

2024-09-08 18:17:01
字體:
供稿:網(wǎng)友
flex要高亮數(shù)據(jù)一般可以使用選中效果或者設置背景,選中效果只能是高亮一條,多條高亮只能設置背景來達到效果。但是原生的DataGrid根本無法達到所要的效果,目前一般就是來改寫原生的DataGrid,只需重新寫一個類來重寫drawRowBackground方法就可以了,代碼如下

復制代碼 代碼如下:


package org.lxh 
{    
    import flash.display.Sprite; 
    import mx.controls.DataGrid; 
    public class SpecialDataGrid extends DataGrid 
    { 
        private var _rowColorFunction:Function;   //用于在外部能通過指定一個方法 去實現(xiàn)改變列的背景色 
        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); 
        } 
    } 
}


用的時候先引入名稱空間 xmlns:control="org.lxh.*",把原來的DataGrid改成下面這樣

復制代碼 代碼如下:


<control:SpecialDataGrid   alternatingItemColors="[0xe3eaf2,0xe8f1f8]" dataProvider="{strArray}" rowColorFunction="colorFunction" doubleClick="planDataGrid_doubleClickHandler(event)" doubleClickEnabled="true"> 
                        <control:columns> 
                            <mx:DataGridColumn dataField="選擇" sortable="false" resizable="false"  showDataTips="true"> 
                                <mx:itemRenderer> 
                                    <fx:Component> 
                                        <mx:CheckBox change="outerDocument.checkChangeHandlerForPlan(event)"/> 
                                    </fx:Component> 
                                </mx:itemRenderer> 
                            </mx:DataGridColumn> 
                        <mx:DataGridColumn dataField="id" headerText="主鍵" visible="false"/> 

                        </control:columns> 
                    </control:SpecialDataGrid>


rowColorFunction屬性用來設置高亮的效果,例如那一列需要高亮,對應的function如下

復制代碼 代碼如下:

(編輯:武林網(wǎng))

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 巧家县| 江口县| 青神县| 余干县| 沭阳县| 东至县| 四平市| 衡山县| 宁都县| 和龙市| 张家界市| 禹城市| 嘉峪关市| 丹阳市| 大余县| 慈利县| 黄大仙区| 施秉县| 潼南县| 六盘水市| 渝北区| 固镇县| 北京市| 株洲市| 手游| 桂阳县| 东方市| 绥滨县| 宁乡县| 闽侯县| 江永县| 三江| 清丰县| 邹城市| 巴中市| 鲁山县| 彭阳县| 齐齐哈尔市| 漳浦县| 梁平县| 丽江市|