flex實(shí)現(xiàn)DataGrid高亮顯示數(shù)據(jù)功能的解決方案
package org.lxh
{
import flash.display.Sprite;
import mx.controls.DataGrid;
public class SpecialDataGrid extends DataGrid
{
private var _rowColorFunction:Function; //用于在外部能通過(guò)指定一個(gè)方法 去實(shí)現(xiàn)改變列的背景色
public function SpecialDataGrid()
{
super();
}
public function set rowColorFunction(f:Function):void
{
this._rowColorFunction = f;
}
public function get rowColorFunction():Function
{
return this._rowColorFunction;
}
//復(fù)寫該方法
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);
}
}
}
用的時(shí)候先引入名稱空間 xmlns:control="org.lxh.*",把原來(lái)的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屬性用來(lái)設(shè)置高亮的效果,例如那一列需要高亮,對(duì)應(yīng)的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;
}
到這里效果就做出來(lái)了
相關(guān)文章
Flex中對(duì)表格中某列的值進(jìn)行數(shù)字格式化保留兩位小數(shù)
表格中展示的比率,對(duì)比率的處理是:保留兩位小數(shù),并向上保留。通過(guò)對(duì)某列的值進(jìn)行數(shù)字格式化來(lái)實(shí)現(xiàn)保留兩位小數(shù)2014-10-10
FLEX ArrayCollection刪除過(guò)濾的數(shù)據(jù)問(wèn)題解決
ArrayCollection添加過(guò)濾器后,調(diào)用removeItemAt()是無(wú)法刪除的,下面有個(gè)不錯(cuò)的解決方法,大家可以參考下2014-06-06
Flex 事件分發(fā)(FlexViewer事件機(jī)制)剝離過(guò)程
本節(jié)主要介紹了如何將FlexViewer里面的事件分發(fā)及監(jiān)聽事件機(jī)制剝離出來(lái)在其他項(xiàng)目中使用,需要的朋友可以參考下2014-07-07
Flex調(diào)Javascript打開新窗口示例代碼
Flex通過(guò)調(diào)用Javascript打開全屏的新窗口新窗口示例代碼 ,具體實(shí)現(xiàn)代碼如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-08-08
Flex實(shí)現(xiàn)的上傳攝像頭拍照并將UI保存為圖片
這篇文章主要介紹了Flex如何實(shí)現(xiàn)上傳攝像頭拍照并將UI保存為圖片,需要的朋友可以參考下2014-05-05
Flex中在Tree綁定數(shù)據(jù)后自動(dòng)展開樹節(jié)點(diǎn)的方法
使用Tree組件在綁定數(shù)據(jù)后自動(dòng)展開所有樹型節(jié)點(diǎn)(不需要用戶再自己點(diǎn)擊展開節(jié)點(diǎn),會(huì)方 便許多),接下來(lái)為大家介紹下具體的實(shí)現(xiàn)2014-01-01
Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表實(shí)現(xiàn)代碼
Flex3 DataGrid拖拽到ClumnChart動(dòng)態(tài)顯示圖表(支持多行同時(shí)拖拽,重復(fù)數(shù)據(jù)不重得添加,添加了圖表右鍵菜單)等等,感興趣的朋友可以了解下啊,或許對(duì)你有所幫助2013-01-01
Flex4 使用itemRenderer 為Tree加線具體實(shí)現(xiàn)
本文為大家詳細(xì)介紹下Flex4如何使用itemRenderer 為Tree加線,感興趣的朋友可以參考下2013-12-12

