flex实现DataGrid高亮显示数据功能的解决方案
网络编程 2021-07-05 11:32www.168986.cn编程入门
原生的DataGrid根本无法达到所要的效果,目前一般就是来改写原生的DataGrid,只需重新写一个类来重写drawRowBackground方法就可以了
flex要高亮数据一般可以使用选中效果或者设置背景,选中效果只能是高亮一条,多条高亮只能设置背景来达到效果。但是原生的DataGrid根本无法达到所要的效果,目前一般就是来改写原生的DataGrid,只需重新写一个类来重写drawRowBackground方法就可以了,代码如下
package .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=".lxh.*",把原来的DataGrid改成狼蚁网站SEO优化这样
<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(monMsg.length > 0){
for(var i:int=0;i<monMsg.length;i++){
if(monMsg.getItemAt(i).id==item.id){
col=0xF10026;
}
}
}
return col;
}
到这里效果就做出来了
代码如下:
package .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=".lxh.*",把原来的DataGrid改成狼蚁网站SEO优化这样
代码如下:
<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(monMsg.length > 0){
for(var i:int=0;i<monMsg.length;i++){
if(monMsg.getItemAt(i).id==item.id){
col=0xF10026;
}
}
}
return col;
}
到这里效果就做出来了
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程