5 Replies Latest reply on Apr 30, 2011 5:47 PM by jfb00

    How can i sort a single AdvancedDataGridColumn in a AdvancedDataGrid?

    Shravan P Level 1

      Hello,

       

      I am using a ADG, which populates the returned data(arraycollection) from database. I'm generating a counter on java side for each returned record and showing that counter in ADGcolumn. I just want to sort that particular column.

       

      When i debug the application, i'm getting the counter count properly but when its showing in ADG, sorting is missing. when i clicks on coloum header, then only its showing in ascending order, i need to show up in ascending order without clicking on column header.

       

      Can anyone help me in this issue??

        • 1. Re: How can i sort a single AdvancedDataGridColumn in a AdvancedDataGrid?
          jfb00 Level 3

          Try this sort:

          var sort:Sort = new Sort();
          sort.fields = [new SortField("FIELD_NAME",true)];
          my_dg.dataProvider.sort = sort;
          my_dg.dataProvider.refresh();
          

           

          Rgds

           

          Johnny

          • 2. Re: How can i sort a single AdvancedDataGridColumn in a AdvancedDataGrid?
            Shravan P Level 1

            Thanks Jfb,

             

            Your code is working fine when we have column without groupingcollection.

            but i have grouping collection in that ADGcolumn. when i applied your code, it's not working.

             

            Anyhow i got the solution:

             

            here is the code for sorting, when ADGcolum have GroupingCollection:

             

             

            import mx.collections.IHierarchicalCollectionView;

             

            import mx.collections.SortField;

             

            import mx.collections.Sort;

             

             

            private function init():void{

             

            var sort:Sort = new Sort();

            sort.fields = [

            new SortField("dataField")];

             

             

             

            // this needs to be called to

             

            // let AdvancedDataGrid finish assigning the dataprovider

            advDataGrid.validateNow();

             

             

             

            // apply sort and call refresh

            IHierarchicalCollectionView(advDataGrid.dataProvider).sort = sort;

            IHierarchicalCollectionView(advDataGrid.dataProvider).refresh();

            }

             

             

            • 3. Re: How can i sort a single AdvancedDataGridColumn in a AdvancedDataGrid?
              jfb00 Level 3

              Hi,

              I have also grouping collection, you need to refresh you grouping collection before do the sort. Like:

                <mx:GroupingCollection id="myGroupedData" source="{acData}" >

               

              myGroupedData.refresh();

              // them the sort

              var sort:Sort = new Sort();

              sort.fields = [

              new SortField("dataField")]; ...

               

              Rgds

               

              Johnny

              • 4. Re: How can i sort a single AdvancedDataGridColumn in a AdvancedDataGrid?
                Shravan P Level 1

                Hi Johnny,

                 

                Thanks for your helpful code, its really working for me.

                 

                but i have an issue, once i apply the sort, i'm getting number '1' and down arrow symbol on ADGcolumnheader.

                i'm using a itemrenderer to get rid of '1' but i need to make invisible the down arrow symbol too.

                 

                sortExpertMode property is working for other columns but not for the column which i'm applying sort.

                 

                Here is the code which disabling the number on columnheader:

                 

                package

                 

                {

                 

                 

                import mx.controls.advancedDataGridClasses.AdvancedDataGridSortItemRenderer;

                 

                import mx.core.UITextField;

                 

                 

                public class ADGSortItemRenderer extends AdvancedDataGridSortItemRenderer

                {

                 

                public function ADGSortItemRenderer()

                {

                 

                //TODO: implement function

                }

                 

                 

                override protected function childrenCreated():void{

                 

                super.childrenCreated();

                 

                 

                //Get reference to sort number text field

                 

                 

                var sortOrderTextField:UITextField = this.getChildAt(0) as UITextField;

                 

                 

                if(sortOrderTextField != null){

                 

                 

                //Hide sort number text field

                sortOrderTextField.includeInLayout =

                 

                false;

                sortOrderTextField.visible =

                false;

                }

                }

                }

                }

                 

                here is the image:

                 

                column_arrow.JPG

                 

                is there any way to disable both the number(1) & down arrow??

                 

                Thanks,

                Shravan P.

                • 5. Re: How can i sort a single AdvancedDataGridColumn in a AdvancedDataGrid?
                  jfb00 Level 3

                  HI,

                  If you want to disable the sort on the datagrid you can use:

                  sortableColumns="true"
                  Rgds

                  Johnny