6 Replies Latest reply on Aug 27, 2009 8:35 AM by Zolotoj

    Restore sort in dataGrid

    Zolotoj Level 3

      After the user saves data I am refreshing dataGrid by pulling data from the server. Once dataProvider is assigned again, previously set sorting is gone. How can I restore the sorting (if any) after setting up dataProvider?



        • 1. Re: Restore sort in dataGrid
          babo_ya Level 3

          Can you not just save the previous Sort class? and when the data is refresh... apply the saved Sort class.


          Hope this helps,



          • 2. Re: Restore sort in dataGrid
            Zolotoj Level 3

            May be I can, but how do I discover what column it's currently sorted on?

            • 3. Re: Restore sort in dataGrid
              babo_ya Level 3

              Sort class requires that you pass in a SortField object. Maybe save that SortField?



              • 4. Re: Restore sort in dataGrid
                Zolotoj Level 3

                Well, I was able to restore sorting simply sending a sort field to the server to sort by.

                But now, I want also to show a sorting arrow.

                Any idea?

                My dataProvider is an XML.

                • 5. Re: Restore sort in dataGrid
                  paul.williams Level 4

                  I imagine the datagrid is resetting when you reassign its dataProvider.

                  If you use a single instance of XMLListCollection as the dataProvider

                  for the grid and assign your XML data to the XMLListCollection's

                  'source' property, your data will update without the grid resetting.

                  Here's a very simple example:


                  <?xml version="1.0" encoding="utf-8"?>
                           import mx.collections.XMLListCollection;
                           private var xmlOriginal : XML =
                                 <item name="Alpha" letter="Z"/>
                                 <item name="Beta" letter="P"/>
                                 <item name="Gamma" letter="X"/>
                                 <item name="Delta" letter="P"/>
                           private var xmlUpdated : XML =
                                 <item name="Alpha" letter="F"/>
                                 <item name="Beta" letter="U"/>
                                 <item name="Gamma" letter="A"/>
                                 <item name="Delta" letter="P"/>
                                 <item name="Epsilon" letter="F"/>
                           private function setDataProvider() : void
                              dataGrid.dataProvider = new XMLListCollection( xmlOriginal..item );
                        label="Simulate Update"
                        click="XMLListCollection( dataGrid.dataProvider ).source = xmlUpdated..item"/>

                  • 6. Re: Restore sort in dataGrid
                    Zolotoj Level 3

                    Yes, looks like it really works!!! Thanks