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?

       

      Thanks

        • 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,

           

          BaBo,

          • 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?

               

              BaBo,

              • 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"?>
                  <mx:Application
                     xmlns:mx="http://www.adobe.com/2006/mxml"
                     layout="vertical"
                     creationComplete="setDataProvider()">
                    
                     <mx:Script>
                        <![CDATA[
                           import mx.collections.XMLListCollection;
                          
                           [Bindable]
                           private var xmlOriginal : XML =
                              <root>
                                 <item name="Alpha" letter="Z"/>
                                 <item name="Beta" letter="P"/>
                                 <item name="Gamma" letter="X"/>
                                 <item name="Delta" letter="P"/>
                              </root>
                             
                           private var xmlUpdated : XML =
                              <root>
                                 <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"/>
                              </root>  
                          
                           private function setDataProvider() : void
                           {
                              dataGrid.dataProvider = new XMLListCollection( xmlOriginal..item );
                           }
                          
                        ]]>
                     </mx:Script>
                    
                     <mx:DataGrid
                        id="dataGrid"/>
                    
                     <mx:Button
                        label="Simulate Update"
                        click="XMLListCollection( dataGrid.dataProvider ).source = xmlUpdated..item"/>
                    
                  </mx:Application>

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

                    Yes, looks like it really works!!! Thanks