0 Replies Latest reply on Dec 11, 2009 1:08 AM by singrahu

    Preserve multi-column sort in AdvancedDataGrid with dataProvider as GroupingCollection


      I have three attributes in my XML object: last name, first name, and age.

      My sample XML looks like:


      <info last="Abc" first="Def" age="20"/>

      <info last="Abc" first="Hij" age="10"/>

      <info last="Xyz" first="Klm" age="25"/>

      <info last="Xyz" first="Opq" age="64"/>

      <info last="Xyz" first="Rst" age="08"/>



      I am using Grouping Collection and AdvancedDataGrid to show the data.

      My problem is to preserve multi-column sort.

      After a refresh happens, the user selected sorting order goes away, and the grid gets sorted by first column only.

      So suppose, user has sorted the table, first ascending by "Age" and then descending by "Name"; after a refresh happens, the grid again gets sorted ascending by "Name".

      We don't want the refresh event to change the sort order, only the data should get refreshed.


      Thanks in advance.


      P.S. I can't use any other datatype like ArrayCollection, to store the data.


      Part of my code looks as follows:





      private var dataXML:XMLListCollection = new XMLListCollection();


      private function refresh(data:Object):void


      dataXML.source = XML(data.result.value).info;


      adGrid.dataProvider = gc;




      private function nameCompareFunction(a:XML, b:XML):int


      return ObjectUtil.stringCompare(a.attribute("last") + a.attribute("first"), b.attribute("last") + b.attribute("first"));


      private function valueSortCompareFunction(a:XML, b:XML):int


      return ObjectUtil.numericCompare(Number(a.attribute("age")), Number(b.attribute("age")));




      <Control:AdvancedDataGrid id="adGrid">


      <mx:GroupingCollection id="gc" source="{dataXML}">


      <mx:GroupingField name="@last" compareFunction="nameCompareFunction"/>






      <mx:AdvancedDataGridColumn id="ADGCName" dataField="@first" headerText="Name" wordWrap="true"/>

      <mx:AdvancedDataGridColumn id="ADGCAge" dataField="@age" headerText="Age" sortCompareFunction="valueSortCompareFunction"/>