检查 Spark DataGrid 单元格以编程方式内容?
我是第一次使用 Spark DataGrid,发现它通常非常有用。既然我已经绘制了网格的内容,我想对它做一些事情,但我对如何继续有点困惑。
我想创建一个函数来运行 DataGrid 中特定列的每个单元格,根据预定义值数组检查每个值;如果找到匹配项,则应通过更改颜色来突出显示该单元格为冲突单元格。
我知道您可以通过使用 getItemRendererAt() 函数并传递列和行索引来访问特定单元格的项目渲染器。但我不知道如何循环遍历每列中的值。
我很可能会做错事,在这种情况下,请随意将我推向正确的道路。同样,如果有可能做我想做的事情,我很想听听如何做。
谢谢!
I'm using the Spark DataGrid for the first time and finding it generally very usable. There's something I'd like to do with the contents of my grid now that I've drawn it though and I'm a bit stuck as how to proceed.
I'd like to make a function that runs through each cell of a certain column in the DataGrid, that checks each value against an Array of predefined values; if it finds a match, it should then highlight the cell as conflicting, by changing its colour.
I know you can access a particular cell's item renderer, by using the getItemRendererAt()
function, and passing the column and row indices. But I can't see how I would, for example, loop through the values in each column.
I may well be going about this all wrong, in which case feel free to push me onto the right path. Equally if it's possible to do what I'm trying to do, I'd love to hear how.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,您应该创建自己的
并将其用作 dataGrid 的 itemRenderer。这样,您将能够根据
的data
属性更改单元格的颜色。以下是如何执行此操作的示例:
Actually, you should create your own
<s:GridItemRenderer />
and use it as an itemRenderer of your dataGrid.This way, you will be able to change the color of the cell depending on the
data
property of the<s:GridItemRenderer />
.Here is an example of how you could do it:
使用上面的示例,还覆盖“设置数据”以在每次更改数据时更改颜色,而不仅仅是在网格创建上
然后接下来的步骤很简单,从数据网格克隆您的 dataProvider ,然后比较两者,如果item改变了,只需将“1”设置为,例如上例中的“不同”标志,然后itemRenderer将调用自身并自动更改颜色
Using the example above, also Override the "set data" to change the color everytime you change the data, and not only on the grid creation
Then the next steps are easy, clone your dataProvider from the datagrid and then compare both, and if the item is changed, just set "1" to ,for example, the flag "different" in the example above and then the itemRenderer will call itself and change de color automatically