如何在 Flex 3 中使用 ItemRenderer 有条件地为 DataGrid 行文本着色
我有一个关于在 Flex 3 DataGrid 中为行着色的问题。我想将“基本”和“低于基本”行中的所有内容设为红色:
<mx:DataGrid id="myGrid"
width="450"
dataProvider="{initDG}"
showHeaders="false">
<mx:columns>
<mx:DataGridColumn dataField="Indicator" itemRenderer="com.dcscore.ColorCells2"/>
<mx:DataGridColumn id="schoolColumn" dataField="Result" fontWeight="bold" itemRenderer="com.dcscore.ColorCells2"/>
</mx:columns>
</mx:DataGrid>
我的 ItemRenderer 是:
package com.mySite {
import mx.controls.Label;
import mx.controls.dataGridClasses.*;
public class ColorCells2 extends Label {
override public function set data(value:Object):void
{
if(value != null)
{
super.data = value;
if(value[DataGridListData(listData).dataField] == "Basic:"){
setStyle("color", 0xFF0000)}
if(value[DataGridListData(listData).dataField] == "Below Basic:"){
setStyle("color", 0xFF0000)}
}
}
}
}
我可以让“基本”和“低于基本”在指示器列中显示为红色。但是,如何使结果列中的相应值显示为红色。我不知道如何引用这些单元格。
简而言之,我想让整个“低于”和“低于基本”行显示为红色。有什么建议吗?
I've got a question about coloring rows in a Flex 3 DataGrid. I'd like to make everything in the "Basic" and "Below Basic" row red:
<mx:DataGrid id="myGrid"
width="450"
dataProvider="{initDG}"
showHeaders="false">
<mx:columns>
<mx:DataGridColumn dataField="Indicator" itemRenderer="com.dcscore.ColorCells2"/>
<mx:DataGridColumn id="schoolColumn" dataField="Result" fontWeight="bold" itemRenderer="com.dcscore.ColorCells2"/>
</mx:columns>
</mx:DataGrid>
My ItemRenderer is:
package com.mySite {
import mx.controls.Label;
import mx.controls.dataGridClasses.*;
public class ColorCells2 extends Label {
override public function set data(value:Object):void
{
if(value != null)
{
super.data = value;
if(value[DataGridListData(listData).dataField] == "Basic:"){
setStyle("color", 0xFF0000)}
if(value[DataGridListData(listData).dataField] == "Below Basic:"){
setStyle("color", 0xFF0000)}
}
}
}
}
I can get "Basic" and "Below Basic" to appear red in the Indicator column. But, how do I get the corresponding values in the Result column to appear red. I don't know how to reference those cells.
In short, I want to make the entire "Below" and "Below Basic" rows appear red. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道要比较的数据项始终是“指标”,则显式引用该数据项,因此无论您渲染哪一列,条件逻辑始终应用于“指标”,从而导致所有列都根据颜色进行着色该数据项的值。
If you know that the data item you are comparing against is always "Indicator" then reference that data item explicitly, so regardless of which column you are rendering your conditional logic is always applied to "Indicator", resulting in all columns being colored based on the value of that data item.