看起来有各种各样的hack可以改变datagrid的行的背景颜色,但是所有这些都似乎在渲染时发生。 :在Adobe Flex中为datagrid行设置背景颜色
我有一个datagrid,我需要将行颜色更改为红色,然后根据绑定ArrayCollection的更改频繁返回正常。所以我正在寻找一种动态改变行颜色的方法。
任何人都可以帮助?显然,随着变化的频繁发生,如果改变行的背景颜色不是一个昂贵的过程,但是beggar不能作为选择器,这将是很好的。
解决方案您必须编写一个自定义组件,我将包含来自我们项目的已清理代码。在您的ActionScript中的某个地方,您需要为每个列写入:
column.itemRenderer = new ClassFactory(CellRenderer);以下是自定义类:
public class CellRenderer extends Label { override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth,unscaledHeight); var g:Graphics = graphics; g.clear(); 每个(var object:array in arrayCollection){ if(object.rowIndex == 0){//或者你的条件是 g.beginFill(0xFFFFC0); g.drawRect(0,0,unscaledWidth,unscaledHeight); g.endFill(); } } } }
It seems like there are various hacks out there to change the background colour of the row of a datagrid but all of them seem to happen at render time.
See: Setting background color for datagrid row in Adobe Flex
I have a datagrid where I need to change row colours to red then back to normal frequently based on changes to the bound ArrayCollection. So I'm looking for a way to change the row colours dynamically.
Can anyone help? Obviously as the changes are happening frequently it would be nice if changing the background colour of the row wasn't an expensive process, but beggar's can't be choosers.
解决方案You'll have to write a custom component, I'll include sanitized code from our project. Somewhere in your ActionScript, you'll need to write this for each column:
column.itemRenderer = new ClassFactory(CellRenderer);Here's the custom class:
public class CellRenderer extends Label { override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { super.updateDisplayList(unscaledWidth, unscaledHeight); var g:Graphics = graphics; g.clear(); for each(var object:Object in arrayCollection) { if (object.rowIndex == 0) { //or whatever your conditions are g.beginFill(0xFFFFC0); g.drawRect(0, 0, unscaledWidth, unscaledHeight); g.endFill(); } } } }
更多推荐
如何动态更改datagrid行的背景颜色?
发布评论