我有一个包含数字的数据网格列。我该怎么办:添加%符号并为其着色
1. add a '%' sign at the end of each number in the column
和
2. make the color either red or green depending on if the number is less than or greater than 0, respectively.
我已经能够做到1或者其他不能同时采用。这里是我有#2,但不是#1:
// my datagrid column:
<mx:AdvancedDataGridColumn dataField="change" itemRenderer="itemrenderers.ColorRenderer" />
// my item renderer:
package itemrenderers
{
import mx.controls.Label;
import mx.controls.dataGridClasses.DataGridListData;
public class ColorRenderer extends Label {
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if (data && data[DataGridListData(listData).dataField] < 0)
{
setStyle("color", 0xA41330); //red
}
else
{
setStyle("color", 0x59A336); //green
}
}
}
}
谢谢,但将所有值更改为'0%',并使它们全部为绿色 –
这是因为我忘记提及您应该从项目渲染器类中移除'updateDisplayList'方法。 – 2DH