5 Replies Latest reply on Dec 22, 2010 11:21 PM by Pol-suma

    How to exclude sorting for first row in an advance datagrid

    Pol-suma

      I have an advance datagrid, by clicking on header we can sort the entire  column but how can we exclude sorting, to the first row? first row shouldnot get sort remaining others have to. can anybody please help me in this regard...

       

       

       

       

      Thanks

      Suma.

        • 1. Re: How to exclude sorting for first row in an advance datagrid
          Flex harUI Adobe Employee

          Custom sortCompareFunction

          1 person found this helpful
          • 2. Re: How to exclude sorting for first row in an advance datagrid
            Pol-suma Level 1

            How can I use this function can you give me a little idea about this?

             

             

             

            Thanks,

            Suma

            • 3. Re: How to exclude sorting for first row in an advance datagrid
              Flex harUI Adobe Employee

              A compareFunctoin looks like:

               

                  function mycompare(a:Object, b:Object):int

                  {

                      if (a < b) return -1;

                      if (a > b) return 1;

                      return 0;

                  }

               

              I would add some test to the begging to always return -1 if a is the first

              item.

              1 person found this helpful
              • 4. Re: How to exclude sorting for first row in an advance datagrid
                Pol-suma Level 1

                Hii, applied this logic but I got stucked at a point,

                 

                when I do the initial sort the summary row stays as the first row. However if the user sorts that column again then the sort order is reversed, and the summary row moves to the last row. How can I make that first row remain in the same place even if i sort it in either ascending or descending. logic which I have applied is below.

                 

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
                   <mx:Script>
                    <![CDATA[
                     import mx.events.AdvancedDataGridEvent;
                     import mx.utils.ObjectUtil;
                     import mx.controls.Alert;
                     import mx.collections.Sort;
                     import mx.collections.SortField;
                      import mx.collections.ArrayCollection;
                            public var advancedgrid:AdvancedDataGrid                
                     [Bindable]
                   private var testData : ArrayCollection = new ArrayCollection([
                         {A:4,B:1, C:'z',summary:true},
                         {A:1,B:2,C:'ab',summary:false},
                         {A:7,B:6,C:'ad',summary:false},
                         {A:2,B:3,C:'ae',summary:false},
                         {A:3,B:4,C:'bf',summary:false},
                         {A:10,B:8,C:'bc',summary:false}
                       
                   ]);  

                  
                 
                        public function compareWithSummary(obj1:Object, obj2:Object):int
                {
                 
                   if (obj1.summary)
                   return -1;
                   else if (obj2.summary)
                   return 1
                   else if (obj1.A < obj2.A)
                   return -1
                   else if (obj1.A > obj2.A)
                   return 1
                   else
                   return 0;
                 

                 
                }

                var  clickA:int=0;
                var  clickB:int=0;
                var  clickC:int=0;    

                private function count(clck:AdvancedDataGridEvent):void{
                  var columnIndex:int=clck.columnIndex;
                  if(columnIndex==0)
                  clickA++;
                  else if(columnIndex==1)
                  clickB++;
                  else
                  clickC++;
                 
                 
                }                                             
                    ]]>
                  </mx:Script>
                <mx:VBox width="100%" height="100%">

                <mx:AdvancedDataGrid id="dpHierarchy" height="80%" width="100%" dataProvider="{testData}" sortExpertMode="true" headerRelease="count(event);">
                   <mx:columns >
                    <mx:AdvancedDataGridColumn headerText="A" dataField="A" textAlign="center" wordWrap="false" width="30" sortCompareFunction="compareWithSummary" sortDescending="true" />
                    <mx:AdvancedDataGridColumn headerText="B" dataField="B" textAlign="center" wordWrap="false" width="35" sortCompareFunction="compareWithSummary" sortDescending="true"/>
                     <mx:AdvancedDataGridColumn headerText="C" dataField="C" textAlign="center" wordWrap="false" width="40" sortCompareFunction="compareWithSummary" sortDescending="true"/>
                   </mx:columns>
                </mx:AdvancedDataGrid>
                <!--<mx:Button label="Sort" height="10%" width="100" click="test();"/>-->
                </mx:VBox>
                </mx:Application>

                 

                Can you  look at this and give me some solution so that we can end up our task on which we are spending days .

                 

                Thanks,

                Suma.

                • 5. Re: How to exclude sorting for first row in an advance datagrid
                  Pol-suma Level 1

                  hiii

                   

                  We tried with the below logic, Still we are facing the same problem.


                  if (obj1.summary)
                                  return col1.sortDescending ? -1 : 1
                          else if (obj2.summary)
                                  return col1.sortDescending ? 1 : -1
                          else if (obj1.A < obj2.A)
                                  return -1
                          else if (obj1.A > obj2.A)
                                  return 1
                          else
                                  return 0;