0

I have an AdvancedDatagrid in my Flex application.

<mx:AdvancedDataGrid id="reportGrid" creationComplete="groupedData.refresh()" width="100%" height="100%" variableRowHeight="true">
                    <mx:dataProvider>
                        <mx:GroupingCollection2 id="groupedData" source="{reportData}"/>
                    </mx:dataProvider>
                </mx:AdvancedDataGrid>

I dynamically assign columns and grouping and summaries to groupedData GroupingCollection2. When I filter the datasource and call groupedData.refresh() the grid refreshes fine. But when I load data, and apply no grouping (add no groupings to the GroupingCollection2), the groupedData.Refresh() does not update the grid to show only the filtered in rows. I have also tried calling the grid's own InvalidateList(), to no avail.

2 Answers2

1

Thanks for the suggestion.

I looked inside the GroupingCollection2.as:

// return if no grouping or groupingFields are supplied
        if (!grouping || grouping.fields.length < 1 )
        {
            super.source = source;
            // dispatch collection change event of kind reset.
            resetEvent =
                    new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
            resetEvent.kind = CollectionEventKind.RESET;
            dispatchEvent(resetEvent);
            return true;
        }

So for some reason Adobe does reset the dataSource if there is no grouping on, which (in my opinion) is a bug, or a bad assumption.

The code above gets called when calling the groupingCollection.refresh(), which is the only way of refreshing the display on the AdvancedDataGrid (that I am aware of)

So, I presume a workaround would be to always have at least 1 grouping on the AdvancedDataGrid. A bit of an undesirable restriction, though.

axel22
  • 32,045
  • 9
  • 125
  • 137
0

My guess is this is happening because the filterFunction that was being applied to the old ArrayCollection is getting wiped out when the data gets loaded. What I would do is make a copy of the old ArrayCollection's filterFunction (and Sort if needed) and then reassign those properties once the data has been loaded.

Here's a quick (and untested) example:

public function loadData(myData:ArrayCollection):void
{
  var filter:Function = reportData.filterFunction;
  reportData = myData;
  reportData.filterFunction = filter;
  reportData.refresh();
}
Jason Towne
  • 8,014
  • 5
  • 54
  • 69