6 Replies Latest reply on Aug 6, 2009 7:46 AM by moutfeh5

    Sort Direction in Data Grid

    moutfeh5 Level 1

      Hi

      i want to know if the clicked column is sorted ASC or DESC,

      While debugging step by step, i found a property in dataGrid whis is "sortDirection"

      but this property is not accessible like this "dataGrid.sortDirection"

       

      is there any method to access this property.

       

      thank you

        • 1. Re: Sort Direction in Data Grid
          Flex harUI Adobe Employee

          That's an unsupported property.  You can get to it using mx_internal, but it can get removed from the API someday.

           

          It is better to use the collection.sort and related properties

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: Sort Direction in Data Grid
            ShardulSingh Level 3

            Hi, for using that kind of property you have to use 'mx_internal'.

            I am putting the code here which can explore you mutch better.

             

             

             

             

             

            <?xml version="1.0"?>

            <mx:Application

            xmlns:mx="http://www.adobe.com/2006/mxml">

             

             

            <mx:Script>

            <![CDATA[

             

             

            import mx.collections.*;

             

             

            import mx.core.mx_internal;

             

             

            use namespace mx_internal;

            [

            Bindable]

             

             

            public var ac:ArrayCollection = new ArrayCollection([

            {No:

            '1', Name:'Charl' },

            {No:

            '2', Name:'Mark' },

            {No:

            '3', Name:'James' },

            {No:

            '4', Name:'Robin' }

            ]);

             

             

             

            private function onCreationComplete(): void

            {

            dg.mx_internal::sortDirection =

            "DESC" ;

            }

            ]]>

             

             

            </mx:Script>

             

             

             

            <mx:DataGrid id="dg" width="350" height="200"

            dataProvider="

            {ac}" creationComplete="onCreationComplete()">

             

             

            <mx:columns>

             

             

            <mx:DataGridColumn dataField="No"/>

             

             

            <mx:DataGridColumn dataField="Name"/>

             

             

            </mx:columns>

             

             

            </mx:DataGrid>

             

             

             

             

             

             

            Hope it will help you.

             

             

            with Regards,

            Shardul Singh Bartwal

             

             

            • 3. Re: Sort Direction in Data Grid
              ShardulSingh Level 3

              Hi Alex,

               

               

              Should we never use 'mx_internal' as I also have read this some where that the classes under this package can be changed any time.

               

               

              Thnx in Advance,

               

              with Regards,

              Shardul Singh Bartwal

              • 4. Re: Sort Direction in Data Grid
                Flex harUI Adobe Employee

                I wouldn't say "never".  Sometimes it is the only way to get something done.   But it is unsupported so when you try to compile against a newer Flex SDK, those properties can go away without notice.  In all of the blog posts examples I've done, I've only had to use it once or twice.

                 

                Alex Harui

                Flex SDK Developer

                Adobe Systems Inc.

                Blog: http://blogs.adobe.com/aharui

                • 5. Re: Sort Direction in Data Grid
                  ShardulSingh Level 3

                  Thnx Alex,

                  for the kind information.

                   

                   

                   

                   

                  with Regards,

                   

                  Shardul Singh Bartwal

                  • 6. Re: Sort Direction in Data Grid
                    moutfeh5 Level 1

                    Thxs for the information

                     

                    I solve it by:

                    When the user click on the column for the first time, i will save the column name in a string colName, and set another varaible (sortDirection) to ascending

                     

                    After it, when the user click on a column, i will check if the column name is equal to colName, if it is i will set sortDirection variable to descending, and if it is not the case i set sortDirection to ascending and colName to the new column name

                     

                     

                    thxs guys for the reply and for the information

                     

                    Regards,

                    -Elie