禁用 Flex DataGrid 中的行
除非我在这里遗漏了一些明显的东西,否则无法禁用 DataGrid 中的一行或多行。 我期望 DataGrid 或 List 组件上有 invalidRows 或 disabledRowIndidices 属性,但这似乎不存在。
我发现了一个“rendererArray”属性,其范围为 mx_internal 并包含数据网格中所有单元格的所有项目渲染器。 因此,我可以检查渲染器内数据的类型和值,并启用或禁用同一行的所有单元格,但这感觉太像黑客了。
有什么建议么?
编辑:我意识到禁用一行可能意味着不同的事情。 就我而言,这意味着即使数据网格的可编辑属性设置为 true,也无法编辑该行。 然而,这也可能意味着无法选择一行,但这不是我想要的。
Unless I'm missing something obvious here, there is no way of disbabling one or more rows in a DataGrid. I would expect a disabledRows or disabledRowIndidices property on the DataGrid or List component but that doesn't seem to exist.
I found a "rendererArray" property which is scoped to mx_internal and contains all itemrenderers of all cells in the datagrid. So I can check the type and the value of the data inside the renderer and enable or disable all cells of the same row, but that feels too much like a hack.
Any suggestions?
Edit: I realize that disabling a row could mean different things. In my case it means not being able to edit the row even when the editable property of the datagrid is set to true. It could however also mean not being able to select a row, but that's not what I'm looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为此,您需要该行的一些数据来表明它不可编辑。 然后,当“itemEditBeginning”检查数据或行索引以启用/禁用 event.preventDefault 的默认行为时...
另一个选项是为您的数据单元格创建自定义 ItemRenderer,但不认为这是您想要的因为你需要为每个细胞制作它。
To do this you will need some data for that row to signify that it is uneditable. Then when the "itemEditBeginning" then check the data or row index to enable/disable the default behavior with event.preventDefault ...
The other option is to make a custom ItemRenderer for your data cell but don't think that is what you want as you would need to make it for each of your cells.
实际上,最好通过“itemEditBeginning”来完成。
在这里查看一个很好的教程:链接文本
actually this is best done via "itemEditBeginning".
Look here for a good tutorial: link text
Alex Harui 在此处提供了一个很好的示例及其源代码,http://blogs.adobe。 com/aharui/2007/06/disabling_list_selection.html 这是一个有点冗长的解决方案,但涵盖了鼠标和键盘与数据网格的交互。 我同意你的观点,令人惊讶的是没有“内置”方法可以做到这一点。
Alex Harui provides a good example with source here, http://blogs.adobe.com/aharui/2007/06/disabling_list_selection.html It's a bit of a lengthy solution, but covers mouse and keyboard interaction with the datagrid. I agree with you, it's surprising that there isn't a "built-in" method to do this.
只需为 DataGrid 的“itemEditBegin”设置一个函数,执行如下操作:
event.preventDefault() 将阻止 DataGrid 将 ItemRenderer 切换到 ItemEditor,从而停止编辑不符合条件的行。
您的 DataGrid 必须可编辑才能正常工作。
这应该可以解决问题。
Just set a function to the "itemEditBegin"of the DataGrid that does something like this:
event.preventDefault() will stop the DataGrid from switching the ItemRenderer to the ItemEditor for so stopping the edition of the row that doesn't meet the criteria.
Your DataGrid must be editable for this to Work.
This should do the trick.