我有一個包含數字的數據網格列。我該怎麼辦:添加%符號併爲其着色
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