AdvancedDataGrid 问题(Bug?)——错误列中的披露图标。 (分层数据,Flex 3.5)
我遇到了一个有趣的问题,并认为值得发布:
在必须使用分层数据在运行时设置数据提供程序的情况下,我正在使用高级数据网格。 adobe 文档并没有真正涵盖此类内容(至少没有达到我可以挖掘的水平)。
以前有人遇到过这个吗?
我唯一能想到的是有点黑客,似乎通过高级网格的公开图标引入了一些奇怪的行为。我在下面包含了一个测试用例:
advancedDataGridProblem.as:
import mx.collections.ArrayCollection;
public var dataProvider:ArrayCollection = new ArrayCollection([{label:"item1"},
{label:"item2", children:[{label:"subItem1"},{label:"subItem2"},
{label:"subItem3"}]},
{label:"item3"}]);
public function init():void{
//using callLater to ensure that the grid has been created before setting DP
this.callLater(setDataProvider,[dataProvider]);
}
public function setDataProvider(list:ArrayCollection):void{
heirData.source = list;
}
和 mxml:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script source="advancedDataGridProblem.as"/>
<mx:AdvancedDataGrid id="advDG" width="100%">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="What the heck?"/>
<mx:AdvancedDataGridColumn headerText="Label" dataField="label"/>
<mx:AdvancedDataGridColumn headerText="Column 2"/>
<mx:AdvancedDataGridColumn headerText="Column 3"/>
</mx:columns>
<mx:dataProvider>
<mx:HierarchicalData id="heirData"/>
</mx:dataProvider>
</mx:AdvancedDataGrid>
</mx:Application>
正如您在运行测试应用程序时所看到的,应该显示在“标签”列中的图标实际上放置在“到底是什么?”中。柱子。如果您将“标签”列拖过来并尝试将其与“到底是什么?”交换。列中,图标保留在原来的位置,但奇迹般的是,之前与“标签”列保持对齐的标签现在已针对图标进行了适当的格式化。将标签列拖出插槽一会将网格恢复到原始状态。
这有点超出了我的想象——有人有什么建议吗?
理想情况下,我想一起解决这个问题,并在运行时照常分配 dataProvider 。
提前致谢!
我很快就会向 adobe 提交一份关于此问题的错误报告,并将链接放入评论中。
I've run into a bit of a funny one and thought it was worth posting:
I'm using an Advanced Data Grid in a case where I've got to set the data provider at runtime using hierarchical data. The adobe docs don't really cover this kind of thing (at least not at the level I could dig to).
Has anyone run into this before?
The only thing I could come up with was a bit hackish and seems to introduce some strange behavior with the disclosure icons of the advanced grid. I've included a test case below:
advancedDataGridProblem.as:
import mx.collections.ArrayCollection;
public var dataProvider:ArrayCollection = new ArrayCollection([{label:"item1"},
{label:"item2", children:[{label:"subItem1"},{label:"subItem2"},
{label:"subItem3"}]},
{label:"item3"}]);
public function init():void{
//using callLater to ensure that the grid has been created before setting DP
this.callLater(setDataProvider,[dataProvider]);
}
public function setDataProvider(list:ArrayCollection):void{
heirData.source = list;
}
and the mxml:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script source="advancedDataGridProblem.as"/>
<mx:AdvancedDataGrid id="advDG" width="100%">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="What the heck?"/>
<mx:AdvancedDataGridColumn headerText="Label" dataField="label"/>
<mx:AdvancedDataGridColumn headerText="Column 2"/>
<mx:AdvancedDataGridColumn headerText="Column 3"/>
</mx:columns>
<mx:dataProvider>
<mx:HierarchicalData id="heirData"/>
</mx:dataProvider>
</mx:AdvancedDataGrid>
</mx:Application>
As you can see when you run the test application, the icons which should show up in the Label column are actually placed in the "What the heck?" column. If you drag the Label column over and attempt to swap it with the "What the heck?" column, the icons remain where they are, but miraculously, the labels that were previously left aligned for the Label column are now formatted appropriately for the icons. Dragging the Label column out of slot one will revert the grid to it's original condition.
This one's a little above my head - anyone have any suggestions?
Ideally, I'd like to get around this hack all together and just assign the dataProvider as per usual at run-time.
Thanks in advance!
I'll be filing a bug report with adobe about this one shortly, and will throw the link into a comment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要解决上面提到的公开图标问题,您可以指定 AdvancedDataGrid 的“treeColumn”属性,传递树数据应位于的列的 id。
显然,前几天我在查看 livedocs 时是盲目的。
干杯!
To resolve the disclosure icon issue noted above, you can specify the AdvancedDataGrid's "treeColumn" property, passing the id of the column which your tree data should be in.
Apparently I was blind the other day looking at the livedocs.
Cheers!
嗯..
经过一个周末的好好摇头和一双新的眼睛,我今天找到了解决问题“简单”部分的方法。
直接设置AdvancedDataGrid的dataProvider比我原来想象的要简单得多;您只需将 ArrayCollection 转换为 HierarchicalData 即可。说实话,我以前尝试过这个,但是 Hierarchical 拼写错误。捂脸。
无论如何,advancedDataGridProblem.as 应该更改为:
mxml 中 dataProvider 的声明也可以删除:
运行此代码,您仍然可以在错误的列中看到披露图标,但至少是设置mxml 中网格的 dataProvider 被删除。这样做还可以进行正确的验证和网格的显示。设置网格的 dataProvider 允许正确的显示验证,显然设置它的 dataProvider 的分层数据源不会调用相同的验证方法,需要用户调整网格大小或程序员以某种方式强制验证(这对于我来说我无法做)。
我会随时向您通报披露图标问题。同时,我希望锁定第一列并将其仅用于这些图标将在我的应用程序中表现良好。我什至可以将这个“缺陷”变成“功能”:P
干杯!
[编辑]
另一种方法可以在使用绑定数据时实现更简单的实现和更少的业务逻辑,如下所示:
advancedDataGridProblem.as:
mxml:
这种方法避免了必须手动无效和验证网格的可能问题。在ActionScript中设置网格的dataProvider后的列表、显示列表等。我对使用此方法的一个小保留是,由于这会在 Flex 3 中创建单向绑定,因此我不确定是否能够使用 HierarchicalData 对象的方法来更改绑定的 ArrayCollection。也就是说,我还没有研究 HierarchicalData 或 AdvancedDataGrid 的源代码,但我毫不怀疑它们确实直接改变了源代码。我会在结果到来时发布结果。
干杯!
Well..
After a weekend to give my head a good shake and a pair of fresh eyes today, I've found a solution for the 'easy' part of my question.
To set the AdvancedDataGrid's dataProvider directly is much simpler than I had originally thought; you just need to cast the ArrayCollection as HierarchicalData. To be honest, I had tried this before, but was spelling Hierarchical incorrectly.. facepalm.
Anyhow, advancedDataGridProblem.as should be changed to:
The declaration of the dataProvider in the mxml can also be removed:
Running this code, you can still see the disclosure icons in the wrong column, but at least the 'hackish' solution of setting the grid's dataProvider in mxml is removed. Doing this also allows proper validation and the grid's display. Setting the grid's dataProvider allows proper display validation, where apparently setting it's dataProvider's hierarchical data's source does not invoke those same validation methods, requiring the user to resize the grid or the programmer to force validation somehow (which for the life of me I couldn't do).
I'll keep you posted on the disclosure icon issue. In the mean time, I expect that locking the first column and using it solely for those icons will do just fine in my application. I may even turn this 'flaw' into a 'feature' :P
Cheers!
[EDIT]
Another method that allows for even easier implementation and less business logic when using bound data is such:
advancedDataGridProblem.as:
The mxml:
This approach circumvents possible issues regarding having to manually invalidate and validate the grid's list, display list, etc. after setting the grid's dataProvider in ActionScript. My one minor reservation using this method is that as this creates a one-way binding in flex 3, I'm unsure as to whether or not I'll be able to use the HierarchicalData object's methods to alter the bound ArrayCollection. That said, I haven't poked around in the source for the HierarchicalData or AdvancedDataGrid, but I wouldn't doubt that they do alter the source directly. I'll post results as they come.
Cheers!