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

首頁 > 開發 > Flex > 正文

flex實現DataGrid高亮顯示數據功能的解決方案

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

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

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

<control:SpecialDataGrid id="planDataGrid" width="100%"  height="100%"  alternatingItemColors="[0xe3eaf2,0xe8f1f8]" dataProvider="{strArray}" rowColorFunction="colorFunction" doubleClick="planDataGrid_doubleClickHandler(event)" doubleClickEnabled="true"> 
                        <control:columns> 
                            <mx:DataGridColumn dataField="選擇" width="50" 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如下
復制代碼 代碼如下:

    private function colorFunction(item:Object, color:uint):uint 
    { 
                    var col:uint=0xe3eaf2; 
                    if(commonMsg.length > 0){ 
                        for(var i:int=0;i<commonMsg.length;i++){ 
                            if(commonMsg.getItemAt(i).id==item.id){ 
                                col=0xF10026; 
                            } 
                        } 
                    } 
                    return col; 

    } 

到這里效果就做出來了
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 淮南市| 老河口市| 榕江县| 海南省| 广南县| 高平市| 旬阳县| 唐河县| 墨脱县| 马山县| 普定县| 黎川县| 中宁县| 宁波市| 英德市| 商洛市| 双辽市| 深泽县| 鄂伦春自治旗| 自治县| 登封市| 岫岩| 丹巴县| 泊头市| 茌平县| 永昌县| 广西| 扶绥县| 邵阳市| 深圳市| 乌鲁木齐市| 长岛县| 盐边县| 多伦县| 安丘市| 桃园市| 仪征市| 黄陵县| 余江县| 天柱县| 兴隆县|