5 Replies Latest reply on Oct 6, 2010 3:11 AM by bindu84

    sorting

    bindu84 Level 1

      i have a data grid , in that i have applied sorting .Now i want to make a copy of that dataprovider with sorted data

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <!-- http://flexonblog.wordpress.com/2009/11/16/sorting-dates-on-arraycolle ction-in-flex/ -->

      <mx:Application

      xmlns:mx="

       

      http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" initialize="init()">

      <mx:Script>

      <![CDATA[

      import

       

       

       

       

       

      mx.collections.SortField;

      import

       

       

       

       

       

      mx.controls.DateField;

      import

       

       

       

       

       

      mx.utils.ObjectUtil;

      import

       

       

       

       

       

      mx.collections.Sort;

      import

       

       

       

       

       

      mx.collections.ArrayCollection;

      [

      Bindable]

      private

       

       

      "Kranthi", Lname:"Kata", dob:"21/10/1972"},

       

      {Fname:

      "Vasanth", Lname:"Lola", dob:"12/01/1980"},

       

      {Fname:

      "Manoj", Lname:"Pati", dob:"16/09/1978"},

       

      {Fname:

      "John McClain", Lname:"Mela", dob:"15/01/1974"},

       

      ]);

       

      private

       

       

      function init():void

      {

      var

       

       

      var

       

       

      var

       

       

      public

       

       

      var myBA:ByteArray = new ByteArray();

      myBA.writeObject( source );

      myBA.position = 0;

       

      return( myBA.readObject() );

      }

       

       

      ]]>

      </mx:Script>

      <mx:DateFormatter

       

      id="dateFormatter" formatString="DD/MM/YY"/>

      <mx:DataGrid

       

      id="dg" width="370" height="212" dataProvider="{arrClldetails}">

      <mx:columns>

      <mx:DataGridColumn

       

      headerText="First Name" dataField="Fname"/>

      <mx:DataGridColumn

       

      headerText="Last Name" dataField="Lname"/>

      <mx:DataGridColumn

       

      headerText="Date of Birth" dataField="dob"/>

      </mx:columns>

      </mx:DataGrid>

      </mx:Application>

       

      But the data i have got in objArray is not sorted . i wnat to staore a copy of data with sorted order how to do that .

       

       

      function cloneDataProvider( source:Object ) :*

      {

       

      objArray:ArrayCollection = cloneDataProvider(dg.dataProvider) as ArrayCollection;

       

       

      }

      sortByName:SortField = new SortField("Fname");

      sort.fields = [sortByName]

      dg.dataProvider.sort=sort;

      dg.dataProvider.refresh();

       

      sort:Sort=new Sort();
      var arrClldetails:ArrayCollection = new ArrayCollection([

      {Fname:

        • 1. Re: sorting
          Anitha Selvaraj Level 2

          Hi,

           

          Check the below code.

           

          <?xml version="1.0" encoding="utf-8"?>
          <!-- http://flexonblog.wordpress.com/2009/11/16/sorting-dates-on-arraycolle ction-in-flex/ -->
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" initialize="init()">
              <mx:Script>
              <![CDATA[
                  import mx.collections.SortField;
                  import mx.controls.DateField;
                  import mx.utils.ObjectUtil;
                  import mx.collections.Sort;
                  import mx.collections.ArrayCollection;
                 
                  [Bindable]
                  private var arrClldetails:ArrayCollection = new ArrayCollection([{Fname:"Kranthi", Lname:"Kata", dob:"21/10/1972"},
                  {Fname:"Vasanth", Lname:"Lola", dob:"12/01/1980"},
                  {Fname:"Manoj", Lname:"Pati", dob:"16/09/1978"},
                  {Fname:"John McClain", Lname:"Mela", dob:"15/01/1974"},
                  ]);
              
                  private function init():void
                  {
                      var  sort:Sort=new Sort();
                      var sortByName:SortField = new SortField("Fname");
                      sort.fields = [sortByName]
                      arrClldetails.sort = sort;
                      arrClldetails.refresh();
             
                      var  objArray:ArrayCollection = new ArrayCollection(arrClldetails.toArray());
                  }
                  public function cloneDataProvider( source:Object ) :* {
                      var myBA:ByteArray = new ByteArray();
                      myBA.writeObject( source );
                      myBA.position = 0;
                      return( myBA.readObject() );
                  }
              ]]>
              </mx:Script>
              <mx:DateFormatter id="dateFormatter" formatString="DD/MM/YY"/>
              <mx:DataGrid id="dg" width="370" height="212" dataProvider="{arrClldetails}">
                  <mx:columns>
                      <mx:DataGridColumn headerText="First Name" dataField="Fname"/>
                      <mx:DataGridColumn headerText="Last Name" dataField="Lname"/>
                      <mx:DataGridColumn headerText="Date of Birth" dataField="dob"/>
                  </mx:columns>
              </mx:DataGrid>
          </mx:Application>

           

          Regards,

          Anitha

          • 2. Re: sorting
            bindu84 Level 1

            Thanx for ur help

            Hi can u tell me one more thing , by this code after click on hide button why sorting icon(triangle  direction icon)is not shown

             

             

            <?xml version="1.0" encoding="utf-8"?>

            <!-- http://flexonblog.wordpress.com/2009/11/16/sorting-dates-on-arraycolle ction-in-flex/ -->

            <mx:Application

            xmlns:mx="

             

            http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" initialize="init()">

            <mx:Script>

            <![CDATA[

            import

             

             

             

             

            mx.collections.SortField;

            import

             

             

            import

             

             

            import

             

             

            import

             

             

            private

             

             

            Bindable]

            private

             

             

            "Kranthi", Lname:"Kata", dob:"21/10/1972"},

             

            {Fname:

            "Vasanth", Lname:"Lola", dob:"12/01/1980"},

             

            {Fname:

            "Manoj", Lname:"Pati", dob:"16/09/1978"},

             

            {Fname:

            "John McClain", Lname:"Mela", dob:"15/01/1974"},

             

            ]);

             

            private

             

             

            function init():void

                    {

                      

            var  sort:Sort=new Sort();

                      

            var sortByName:SortField = new SortField("Fname");

                        sort.fields = [sortByName]

                        arrClldetails.sort = sort;

                        arrClldetails.refresh();

              

                          objArray =

            new ArrayCollection(arrClldetails.toArray());

                    }

             

            private

             

             

            false;

            dg.dataProvider = objArray;

            }

             

            ]]>

            </mx:Script>

            <mx:DateFormatter

             

            id="dateFormatter" formatString="DD/MM/YY"/>

            <mx:DataGrid

             

            id="dg" width="370" height="212" dataProvider="{arrClldetails}">

            <mx:columns>

            <mx:DataGridColumn

             

            headerText="First Name" dataField="Fname"/>

            <mx:DataGridColumn

             

            headerText="Last Name" dataField="Lname"/>

            <mx:DataGridColumn

             

            headerText="Date of Birth" dataField="dob"/>

            </mx:columns>

            </mx:DataGrid>

            <mx:Button

             

            label="hide" click="hideColumn()"/>

             

            </mx:Application>

            function hideColumn()

            {

            dg.columns[1].visible =

            var arrClldetails:ArrayCollection = new ArrayCollection([

            {Fname:

            var objArray:ArrayCollection;

            [

            mx.collections.ArrayCollection;
            mx.collections.Sort;
            mx.utils.ObjectUtil;
            mx.controls.DateField;
            • 3. Re: sorting
              Anitha Selvaraj Level 2

              can you post your code properly. The above code is not in the proper order right?


              • 4. Re: sorting
                bindu84 Level 1

                <?xml version="1.0" encoding="utf-8"?>

                <!-- http://flexonblog.wordpress.com/2009/11/16/sorting-dates-on-arraycolle ction-in-flex/ -->

                <mx:Application

                xmlns:mx="

                http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" initialize="init()">

                <mx:Script>

                <![CDATA[

                import

                 

                 

                import

                 

                 

                import

                 

                 

                import

                 

                 

                import

                 

                 

                private

                 

                 

                Bindable]

                private

                 

                 

                "Kranthi", Lname:"Kata", dob:"21/10/1972"},

                 

                {Fname:

                "Vasanth", Lname:"Lola", dob:"12/01/1980"},

                 

                {Fname:

                "Manoj", Lname:"Pati", dob:"16/09/1978"},

                 

                {Fname:

                "John McClain", Lname:"Mela", dob:"15/01/1974"},

                 

                ]);

                 

                private

                 

                 

                function init():void

                {

                          

                var  sort:Sort=new Sort();

                          

                var sortByName:SortField = new SortField("Fname");

                            sort.fields = [sortByName]

                            arrClldetails.sort = sort;

                            arrClldetails.refresh();

                            objArray =

                new ArrayCollection(arrClldetails.toArray());

                }

                 

                private

                 

                 

                false;

                dg.dataProvider = objArray;

                }

                 

                ]]>

                </mx:Script>

                <mx:DateFormatter

                 

                id="dateFormatter" formatString="DD/MM/YY"/>

                <mx:DataGrid

                 

                id="dg" width="370" height="212" dataProvider="{arrClldetails}">

                <mx:columns>

                <mx:DataGridColumn

                 

                headerText="First Name" dataField="Fname"/>

                <mx:DataGridColumn

                 

                headerText="Last Name" dataField="Lname"/>

                <mx:DataGridColumn

                 

                headerText="Date of Birth" dataField="dob"/>

                </mx:columns>

                </mx:DataGrid>

                <mx:Button

                 

                label="hide" click="hideColumn()"/>

                 

                </mx:Application>

                function hideColumn()

                {

                dg.columns[1].visible =

                var arrClldetails:ArrayCollection = new ArrayCollection([

                {Fname:

                var objArray:ArrayCollection;

                [

                mx.collections.ArrayCollection;
                mx.collections.Sort;
                mx.utils.ObjectUtil;
                mx.controls.DateField;
                mx.collections.SortField;
                • 5. Re: sorting
                  bindu84 Level 1

                  <?xml version="1.0" encoding="utf-8"?>
                  <!-- http://flexonblog.wordpress.com/2009/11/16/sorting-dates-on-arraycolle ction-in-flex/ -->
                  <mx:Application
                  xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" initialize="init()">
                  <mx:Script>
                  <![CDATA[
                  import mx.collections.SortField;
                  import mx.controls.DateField;
                  import mx.utils.ObjectUtil;
                  import mx.collections.Sort;
                  import mx.collections.ArrayCollection;
                  private var objArray:ArrayCollection;
                  [Bindable]
                  private var arrClldetails:ArrayCollection = new ArrayCollection([
                  {Fname:"Kranthi", Lname:"Kata", dob:"21/10/1972"},

                  {Fname:"Vasanth", Lname:"Lola", dob:"12/01/1980"},

                  {Fname:"Manoj", Lname:"Pati", dob:"16/09/1978"},

                  {Fname:"John McClain", Lname:"Mela", dob:"15/01/1974"},

                  ]);

                  private function init():void
                  {
                              var  sort:Sort=new Sort();
                              var sortByName:SortField = new SortField("Fname");
                              sort.fields = [sortByName]
                              arrClldetails.sort = sort;
                              arrClldetails.refresh();
                              objArray = new ArrayCollection(arrClldetails.toArray());
                  }

                  private function hideColumn()
                  {
                  dg.columns[1].visible = false;
                  dg.dataProvider = objArray;
                  }

                  ]]>
                  </mx:Script>
                  <mx:DateFormatter id="dateFormatter" formatString="DD/MM/YY"/>
                  <mx:DataGrid id="dg" width="370" height="212" dataProvider="{arrClldetails}">
                  <mx:columns>
                  <mx:DataGridColumn headerText="First Name" dataField="Fname"/>
                  <mx:DataGridColumn headerText="Last Name" dataField="Lname"/>
                  <mx:DataGridColumn headerText="Date of Birth" dataField="dob"/>
                  </mx:columns>
                  </mx:DataGrid>
                  <mx:Button label="hide" click="hideColumn()"/>

                  </mx:Application>