Flex 高级数据网格排序
我有一个由客户数据填充的 AdvancedDataGrid。每个客户都有 3 个月度产品 (1, 3, 6),还有一个 passed
字段,用于指定客户是否有资格获得任何月度产品。
现在网格按字母顺序对客户数据进行排序,这是一件好事,但它没有对每月的产品进行排序,这不是一件好事。
dataProvider 看起来像这样。 (我按资助者分组。)
{Funder:"Customer1", Product:"1 Month", Passed:"False"},
{Funder:"Customer1", Product:"3 Month", Passed:"True"},
{Funder:"Customer1", Product:"6 Month", Passed:"True"},
{Funder:"Customer2", Product:"1 Month", Passed:"False"},
{Funder:"Customer2", Product:"3 Month", Passed:"False"},
{Funder:"Customer2", Product:"6 Month", Passed:"False"}
然后我在网格中得到的结果看起来像这样
----------------------------------------
| Funder & Products | Product Passed |
----------------------------------------
| Customer1 | |
| 6 Month | True |
| 3 Month | True |
| 1 Month | False |
| Customer2 | |
| 3 Month | False |
| 6 Month | False |
| 1 Month | False |
----------------------------------------
对于对产品进行排序还有帮助吗?
编辑:
这是我用于网格的代码
<mx:AdvancedDataGrid id="myADG"
width="100%" height="100%"
initialize="gc.refresh();"
folderClosedIcon="{null}"
folderOpenIcon="{null}"
defaultLeafIcon="{null}">
<mx:dataProvider>
<mx:GroupingCollection id="gc" source="{mCustomerData}">
<mx:grouping>
<mx:Grouping>
<mx:GroupingField name="Funder"/>
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollection>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Product"
headerText="Funder & Products"/>
<mx:AdvancedDataGridColumn dataField="Passed"
headerText="Product Passed"/>
<mx:AdvancedDataGridColumn dataField="Passed"
headerText="Product Failed"/>
</mx:columns>
</mx:AdvancedDataGrid>
I have an AdvancedDataGrid that is being populated by customer data. Each customer has 3 monthly products(1, 3, 6), and also a passed
field specifying whether the customer qualifies for any of the monthly products.
Now the grid is sorting the customer data alphabetically, which is a good thing, but it isnt sorting the monthly products, not so good thing.
The dataProvider looks something like this. (I am grouping by Funder.)
{Funder:"Customer1", Product:"1 Month", Passed:"False"},
{Funder:"Customer1", Product:"3 Month", Passed:"True"},
{Funder:"Customer1", Product:"6 Month", Passed:"True"},
{Funder:"Customer2", Product:"1 Month", Passed:"False"},
{Funder:"Customer2", Product:"3 Month", Passed:"False"},
{Funder:"Customer2", Product:"6 Month", Passed:"False"}
Then results that I get in the grid looks something like this
----------------------------------------
| Funder & Products | Product Passed |
----------------------------------------
| Customer1 | |
| 6 Month | True |
| 3 Month | True |
| 1 Month | False |
| Customer2 | |
| 3 Month | False |
| 6 Month | False |
| 1 Month | False |
----------------------------------------
Any help on getting the products sorted as well?
EDIT:
Here is the code I use for the grid
<mx:AdvancedDataGrid id="myADG"
width="100%" height="100%"
initialize="gc.refresh();"
folderClosedIcon="{null}"
folderOpenIcon="{null}"
defaultLeafIcon="{null}">
<mx:dataProvider>
<mx:GroupingCollection id="gc" source="{mCustomerData}">
<mx:grouping>
<mx:Grouping>
<mx:GroupingField name="Funder"/>
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollection>
</mx:dataProvider>
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Product"
headerText="Funder & Products"/>
<mx:AdvancedDataGridColumn dataField="Passed"
headerText="Product Passed"/>
<mx:AdvancedDataGridColumn dataField="Passed"
headerText="Product Failed"/>
</mx:columns>
</mx:AdvancedDataGrid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
遇到了完全相同的问题,并在 Adobe 网站上找到了解决方案:
How to sort items inside group in AdvancedDataGrid
您可以编写一个比较函数并将其用于分组字段。
Had exactly the same problem and found the solution on Adobe's website:
How to sort items within group in AdvancedDataGrid
You can write a compare function and use it on the grouping field.
好的,所以我找到了一个适合我的解决方案。如下。
基本上,在
creationComplete
上,我调用sortData
函数来执行以下操作。希望看到另一种方法,因为我不能认为这是唯一的方法
Okay, so I found a solution that works for me. Here follows.
Basically, on
creationComplete
I call thesortData
function that does the following.Hope to see another way of doing this, as I cant think that this is the only way of doing it
出于所有意图和目的,网格不会对数据进行排序。它只是按照您指定的顺序显示您提供的数据。 dataProvider 必须由您排序,网格将相应更新。
如果您通过单击列标题进行排序,请查看 sortCompareFunction
如果您使用的是 ArrayCollection 或 XMLListCollection,请查看此 有关如何排序的文档。
For all intents and purposes, a Grid doesn't sort data. It just displays the data you provide it in the order you specified. The dataProvider must be sorted by you and the grid will update accordingly.
If you're sorting by clicking on column headers, then take a look at the sortCompareFunction on the AdvancedDataGridColumn
If you're using an ArrayCollection or XMLListCollection, then take a look at this documentation on how to sort it.