2 Replies Latest reply on Jun 8, 2011 11:29 AM by run,ryan!

    Keep sorting and sort arrows after datagrid dbprovider changed

    run,ryan! Level 3

      I followed this tutorial http://justinjmoses.wordpress.com/2008/06/26/flex-keeping-the-sort-on-a-datagrid-when-you- change-the-dataprovider/

      created listeners


      that keeps old sorting of datagrid after dataprovider changed, but displaying sort arrow on the wrong column(always the 1st column), how do I fix it?


                public function FilterDatagrid()
                     addEventListener(mx.events.CollectionEvent.COLLECTION_CHANGE, onDataGridDataChange, false, 0, true);
                private var currentSort:mx.collections.Sort;
                private function onDataGridDataChange(evt:CollectionEvent):void
                     //get the new data collection
                     var ac:ArrayCollection = this.dataProvider as ArrayCollection;
                     //attach the collection change event
                     ac.addEventListener(CollectionEvent.COLLECTION_CHANGE, onCollectionChanged,false,0,true);
                     //if a sort was in place before the data was changed, make sure you apply the sort to this new data
                     if (currentSort != null)
                          ac.sort = currentSort;
                private function onCollectionChanged(evt:CollectionEvent):void
                     if (evt.kind == CollectionEventKind.REFRESH)
                          var ac:ArrayCollection = evt.currentTarget as ArrayCollection;
                          currentSort = ac.sort;