设置高级数据网格单元格格式
我有一个关于渲染高级数据网格单元的快速问题。
我需要根据条件以编程方式为数据网格的单元格着色。 比方说,股票报价。 如果与前一天相比有所增加,则我需要将单元格涂成绿色,而当减少时,我需要将单元格涂成红色。
现在,这里重要的部分是,我需要动态地执行这些操作,这意味着,当用户启用比较/条件时,单元格就会被着色。 当用户禁用比较时,它会再次恢复到默认行为。
我知道我必须使用渲染器。 但不确定如何将它用于细胞以及动态地使用它。 谁能解释一下如何去做吗?
谢谢
I have a quick question about rendering the advanceddatagrid cells.
I need to programatically color the cell of the datagrid based on the conditions. Lets say, the stock quotes. If there is an increase from the previous day, I need to have the cell colored in GREEN and in RED, when there is a decrease.
Now, the important part here is, I need to do these things dynamically, which means, when the user enables the comparison/conditions, then the cells are colored. And when the user disables the comparison, then it again goes back to its default behavior.
I know I have to use renderers. But not sure, how to use it for the cells and that too dynamically. Can anyone please explain how to go for it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
项目渲染器是用于定义组件的“项目”或子组件的外观的组件。 对于 ADG,“项目”是单个单元格。 您可以创建一个完全自定义的类来充当渲染器(假设它实现了某些必需的接口),或者在大多数情况下,您可以扩展现有组件。 由于 ADG 单元格的默认渲染器不支持背景颜色,因此您必须创建或扩展一个支持背景颜色的组件并将其用作渲染器。 这是这些教程(在以下问题中链接到)的基本前提:
在 Adobe Flex 中设置数据网格行的背景颜色
创建支持背景颜色的 itemRenderer 后,您有两个选项可以定义“条件”; 在 itemRenderer 内部或使用 ADG 的 styleFunction (另外要求您的 itemRenderer 定义“背景”样式)。
在您的情况下,您可以在发送到每个单元格的数据中包含今天和昨天的股票价格值,并比较两者以确定用于绘制背景的颜色。 同样,上面提供的教程链接中有更多相关内容。 在 itemRenderer 或 styleFunction 中,您可以比较 itemRenderer/styleFunction 的数据对象(对应于您正在查看的行)的属性,例如:
要“切换”自定义单元格颜色,请在自定义渲染器和默认渲染器之间切换(无色)渲染器。 换句话说,当您需要显示颜色时,将 itemRenderer 属性设置为自定义 itemRenderer 类;当您需要“默认行为”时,将其设置为“null”。
Item renderers are components used to define the appearance of a component's "items" or subcomponents. In the case of the ADG, the "items" are the individual cells. You can create a completely custom class to function as the renderer (given it implements certain required interfaces) or, in most cases, you extend an existing component. Since the default renderer for ADG cells doesn't support background colors, you have to create or extend a component that does and use that as the renderer. That is the basic premise that these tutorials, linked to in the following question, work from:
Setting background color for datagrid row in Adobe Flex
After creating an itemRenderer that supports a background color, you have two options as to where you can define your "conditions"; inside of the itemRenderer or using the ADG's styleFunction (additionally requiring that your itemRenderer defines a "background" style).
In your case, you could include both today's and yesterday's stock price values in the data sent to each cell and compare the two to determine the color used to draw the background. Again, more on that in the tutorial links provided above. In either the itemRenderer or the styleFunction, you would compare properties on the itemRenderer's/styleFunction's data object (corresponding to the row you're looking at), e.g.:
To "toggle" custom cell colors, switch between your custom renderer and the default (colorless) renderer. In other words, set the itemRenderer property to your custom itemRenderer class when you need display the colors and set it to "null" when you want the "default behavior".