Search code examples
apache-flexactionscriptmxml

keep my sort after updating the dataprovider's data


I have a datagrid where the data in the dataprovider changes every 30 seconds automatically. Everytime it does, if I chose to sort the column by clicking on the header, it will revert back to the default sort (before I clicked on the header). I want to know how I can control the sorting so that if I had clicked on it previously, it will remain sorted as so the next 30 seconds.

<mx:DataGrid id="id" width="100%" height="100%">
                        <mx:columns>
                            <mx:DataGridColumn dataField="@col1" headerText="Type1" itemRenderer="itemRenderer" />
                            <mx:DataGridColumn dataField="@col2" headerText="Type2" itemRenderer="itemRenderer" />
                        </mx:columns>
                        <mx:dataProvider>
                            {xmllist_extractedfromAnotherSourceEvery30Seconds}
                        </mx:dataProvider>
</mx:DataGrid>

Solution

  • A guess... The sort order is stored within the dataProvider (ArrayCollection), and it gets lost when you re-assign a new dataProvider.

    You could either:

    • update the dataProvider using ArrayCollection update functions, instead of re-assigning it

    • if not possible, get the ISort from the dataProvider before changing it; then apply this ISort to the new dataProvider after loading (and remember to refresh() the dataProvider)