Flex 高级数据网格排序

发布于 2024-09-10 03:47:06 字数 2361 浏览 9 评论 0原文

我有一个由客户数据填充的 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 &amp; 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三生池水覆流年 2024-09-17 03:47:07

遇到了完全相同的问题,并在 Adob​​e 网站上找到了解决方案:

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.

感悟人生的甜 2024-09-17 03:47:06

好的,所以我找到了一个适合我的解决方案。如下。

基本上,在creationComplete上,我调用sortData函数来执行以下操作。

private function sortData():void {
    var sort:Sort = new Sort();
    var sortField:SortField = new SortField("Product");

    sort.fields = [sortField];        // Set 'Product' as the field to be sorted on
    myADG.dataProvider.sort = sort;   // Add the sort to the dataProvider of the dataGrid
    gc.source.refresh();              // Refresh the GroupCollection
}

希望看到另一种方法,因为我不能认为这是唯一的方法

Okay, so I found a solution that works for me. Here follows.

Basically, on creationComplete I call the sortData function that does the following.

private function sortData():void {
    var sort:Sort = new Sort();
    var sortField:SortField = new SortField("Product");

    sort.fields = [sortField];        // Set 'Product' as the field to be sorted on
    myADG.dataProvider.sort = sort;   // Add the sort to the dataProvider of the dataGrid
    gc.source.refresh();              // Refresh the GroupCollection
}

Hope to see another way of doing this, as I cant think that this is the only way of doing it

荆棘i 2024-09-17 03:47:06

出于所有意图和目的,网格不会对数据进行排序。它只是按照您指定的顺序显示您提供的数据。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文