6 Replies Latest reply on Mar 30, 2012 8:28 AM by jfb00

    AdvancedDatagrid Sort

    jfb00 Level 3

      Hi,

      I am trying to do a generic sort function for ADG such as:

      public static function sortCompareFunction(obj1:Object, obj2:Object, gc:AdvancedDataGridColumn):int {

               return ObjectUtil.numericCompare(Number(obj1[gc.dataField].toString().replace(',','')), Number(obj2[gc.dataField].toString().replace(',','')));

              }

       

      I got the idea from here:

      http://cookbooks.adobe.com/post_Sorting_numeric_values_in_a_Flex_DataGrid-2881.html

       

      ArgumentError: Error #1063: Argument count mismatch on assets.valueObjects::Utils$/sortCompareFunction(). Expected 3, got 2.

      I am using SDK 4.5.1, can anyone help with this?

      Thanks!

        • 1. Re: AdvancedDatagrid Sort
          jfb00 Level 3

          bump1

          • 2. Re: AdvancedDatagrid Sort
            jfb00 Level 3

            bump2

            nobody can give an idea?

            • 3. Re: AdvancedDatagrid Sort
              Sathyamoorthi Level 2

              Hi,

               

                   You can't do in this way.

               

                   create your own datagridcolumn and write this sortcompare function there

               

                  

              public  function sortCompareFunction(obj1:Object, obj2:Object):int

              {

                       return ObjectUtil.numericCompare(Number(obj1[dataField].toString().replac e(',','')), Number(obj2[dataField].toString().replace(',','')));

              }

               

              this will suely work!!!

              • 4. Re: AdvancedDatagrid Sort
                jfb00 Level 3

                Hi,

                Thanks for you reply and help.

                This is what i am trying to avoid becuase I have so many datagrids with many columns. I am trying to create a generic function in my utils.as file.

                It is not way to do it?

                Best,

                • 5. Re: AdvancedDatagrid Sort
                  Sathyamoorthi Level 2

                  Hi,

                   

                       I ask you to extend dataridcolumn and create your custom datagird column. this is what you really need.

                   

                  DgdColumn2.as

                   

                  package Dg2

                  {

                      public class DgdColumn2 extends DataGridColumn

                      {     

                          public function SrtCmpFnNumeric(objItem1:Object, objItem2:Object):int

                          {

                              return ObjectUtil.numericCompare(objItem1[dataField], objItem2[dataField]);

                          }       

                      }

                   

                  }

                   

                  in your main.as

                   

                  var dgdClmn:DgdColumn2;

                  var column:Array = new Array();

                   

                  for(var i:int = 0; i < 10; i++)

                  {

                      dgdClmn = new DgdColumn2();

                      dgdClmn.sortCompareFunction = dgdClmn.SrtCmpFnNumeric;

                      column.push(dgdClmn);

                  }

                   

                  datagrid.columns = column;

                  • 6. Re: AdvancedDatagrid Sort
                    jfb00 Level 3

                    That works, only if I have to construct the columns dynamic.

                    Can I use this in a datagrid that it doesn't created by that way?

                    Thanks!