Keep sorting and sort arrows after datagrid dbprovider changed

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?
                   //constructor
          public function FilterDatagrid()
               super();
               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;
                    ac.refresh();
          private function onCollectionChanged(evt:CollectionEvent):void
               if (evt.kind == CollectionEventKind.REFRESH)
                    var ac:ArrayCollection = evt.currentTarget as ArrayCollection;
                    currentSort = ac.sort;

the datagrid uses XML as dataprovider and uses labelFunction and sortCompareFunction on each column, not sure if it matters

Similar Messages

Maybe you are looking for

  • MP3 plays in iTunes but not iPhone

    I have the iPhone 3G running 2.0.2 software. I have a bunch of .mp3 files that I loaded into iTunes and then sync'd with my iPhone. There is one mp3 that plays just fine in iTunes but will not play on my iPhone. When I select the song on the iPhone,

  • Error printing in Reader X

    I was printing a PDF using Adobe Acorbat Reader X. I printed one doucment just fine. Then when I selected the second document I got an error "The document could not be printed." Then a second error "There were no pages selected to print." I closed Re

  • Defect in Acrobat XI for mac osx

    Using Acrobat XI for mac osx I opened a bank statement pdf. I redacted the account numbers. It gave me option to remove hidden metadata. I removed the hidden metadata. I saved the document and it removed character "I" from many places in the document

  • Problem in data coming to PI system from SAP?

    Hello All, I facing problem with the data coming from SAP system to PI system. in VT02n give the shipment number and after that create some thing and trigger an IDOC. when the data come to PI system, i checked in moni i saw that  data getting mixed.

  • I can't copy and paste from Pages anymore!

    I'm running on Yosemite and newest Pages Version (updated today) and now I can't copy texts from Pages (e.g. into InDesign or Photoshop) anymore. I have to convert it into simple text, then open it with TextEdit to make copy & paste possible again. P