Flex AdvancedDataGrid sort

I have an AdvancedDataGrid that is populated with client data. Each client has 3 monthly products (1, 3, 6), as well as a field passedthat determines whether the client is suitable for any of the monthly products.

Now the grid sorts the customer data alphabetically, which is good, but this is not a sorting of monthly products, and not a very good thing.

DataProvider looks something like this. (I am grouping 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 the results that I get in the grid look 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 sorting products 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 &amp; Products"/>
        <mx:AdvancedDataGridColumn dataField="Passed"
                                   headerText="Product Passed"/>
        <mx:AdvancedDataGridColumn dataField="Passed"
                                   headerText="Product Failed"/>
    </mx:columns>
</mx:AdvancedDataGrid>
+3
source share
3 answers

, , . .

, 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
}

, , .

+3

. , , . DataProvider , .

, , sortCompareFunction AdvancedDataGridColumn

ArrayCollection XMLListCollection, , .

+1

Had the exact same problem and found a solution on the Adobe website:

How to sort items within a group in AdvancedDataGrid

You can write a comparison function and use it in the grouping field.

+1
source

Source: https://habr.com/ru/post/1754760/


All Articles