在数据网格上排序时 Flex 的 itemrenderer 问题
请按照我的解释在这里:
- 我有一个数据网格,其中包含一个具有 3 列的数据提供程序,
- 其中 3 列之一是按钮 itemrenderer,其他是整数
- 我将 4 行放入数据网格
- 中我在一行中设置了一个按钮以禁用,其他为启用
- 然后我尝试通过“单击”具有整数列(而不是按钮列)的列标题对数据网格进行排序。
- 预期的结果是禁用按钮将与其初始行一起出现。但真正的结果是,当您单击排序 2-3 次时,按钮(所有行中)将具有连线行为。禁用的按钮有时会返回启用状态,有时会禁用但停留在错误的行上。
有没有人对此有解决方案?
Please follow my explanation here :
- I have a datagrid which holds a dataprovider that has 3 columns
- one of those 3 columns is button itemrenderer, others are integer
- I put 4 row into the datagrid
- I set a button in a row to disable, others are enabled
- Then I try sorting the datagrid by "click" on the column header that has integer column (not button column)
- The expected result is that the disable button would go with its initial row. But the real result is when you click to sort 2-3 times, the buttons (in all rows) will have a wired behavior. The disabled button sometimes back to enable, and sometimes disabled but stay on a wrong row.
Is there anyone got a solution on this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果网格有滚动条,则 ItemRendrer 始终会被重用,从而导致奇怪的行为。
一篇关于 ItemRenderer 生命周期的好文章:
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html彼得·恩特 (Peter Ent) 着
ItemRendrer are always reused if the grid has scrollbars and hence resulted into the wierd behavior.
A good article to read about ItemRenderer life cycle:
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html by Peter Ent
如果您的按钮项渲染器是自定义的,您可能只需要覆盖“设置数据”。排序时会重新使用 itemrenderer 并更改数据。项目渲染器本身不会移动。
发布您的项目渲染器的代码,我们可以提供更好的答案。
If your button item renderer is custom, you probably just need to override "set data". The itemrenderers are re-used and the data is changed when sorting. The item renderers themselves don't move.
Post the code of your item renderer and we can provide a better answer.
这听起来像是您没有正确地重新初始化渲染器。每次实现自定义 itemRenderer 时,最好是重写数据访问器(字面意思是数据)。然后,例如,如果“blue”属性为 true,则将 uicomponent 着色为蓝色,则不应考虑这一点,否则 uicomponent 不会着色,因为 itemRenderers 回收每个基于列表的组件的内容。也许这个特定的渲染器之前被分配给另一个数据对象,然后 uicomponent 可能已经是蓝色的。看 ?
That sounds like you're not properly reinitializing your renderer. Every time you implement a custom itemRenderer, the best is to override the data accessors (literally data). Then if, for instance, you color an uicomponent in blue if the "blue" property is true, you should not consider that, otherwise, the uicomponent is not colored, because of the itemRenderers recycling stuff of every list-based component. Maybe this particular renderer was assigned to another data object just before, and then maybe the uicomponent already is blue. See ?
感谢您的帮助。
但是,无论如何我都没有自定义该按钮。它只是 Flex 中的一个常见按钮,但我确实使用 itemrenderer 将其放在一列中。这是在网格中构建按钮控件的代码
这是我的使用方法
thank you for your help.
However, I didn't customize the button in anyway. It is just a usual button in flex but I did put it in a column by using itemrenderer. Here's the code for building a button control in a grid
and here is how I use it