Hi no problem! Thanks again for the helpful reply.

I am a bit clueless about this and so I can't work out how to access the
column object within the sort method. All my coding is within actionscript
classes and what I have is a View component that contains multiple
AdvancedDataGrids. They are created dynamically at runtime as only then do I
know how many I need. In the View class I have methods like the following:

private function createGrids(dataUpdate:Object):void
{
    var tables:Array = dataUpdate[TABLES];
    for each (var table:Object in tables)
    {
        var gridName:String = table[TABLE_NAME];
        var columns:Array= table[TABLE_COLUMNS];
        var grid:MyAdvancedDataGrid;
        // if grid does not exist then create it, otherwise update columns
in existing grid
        if (mDataGrids[gridName] == null)
        { 
            grid = new MyAdvancedDataGrid(gridName);
        }
        else 
        { 
            grid = mDataGrids[gridName]
        }

        createColumns(grid, columns);
    }
}

private function createColumns(grid:AdvancedDataGrid, columns:Array)
{
    for each (var column:Object in columns)
    {
        var adgColumn:AdvancedDataGridColumn = new
AdvancedDataGridColumn(column[DATA_FIELD]);
        adgColumn.dataField = column[DATA_FIELD];
        adgColumn.headerText = column[HEADER];       
        if (column[DATA_FIELD] == "id")                         
            adgColumn.sortCompareFunction = compareIdExcludeSummaryRow;
    } 
}

private function compareIdExcludeSummaryRow(obj1:Object, obj2:Object):int
{
        if (obj1.summaryRow)
// TODO find col1!!!!
          return col1.sortDescending ? -1 : 1
        else if (obj2.summaryRow)
          return col1.sortDescending ? 1 : -1
        else if (obj1.id < obj2.id)
          return -1
        else if (obj1.id > obj2.id)
          return 1
        else
          return 0;
}

So createColumns() takes a newly constructed AdvancedDataGrid and an array
of column descriptions and dynamically creates the columns for the grid
(again the number of columns and their headers / datafields are only known
at runtime). So within this method I need to assign a different custom sort
method to each of the columns, and I guess I need to create these sort
methods dynamically (another problem and any pointers appreciated here as
well...). 

For now to test this you will see above that I am just hardcoding a method
to sort on the id field but exclude the summary row. However even within
this method I am not sure how to access the column object to determine
whether it is sort ascending / descending? The same method will have been
assigned as the sort method for AdvancedDataGridColumns in more than one
grid, so within the sort method I need to find out which grid has called it,
and then access the column in that grid (or else determine the column
directly). Any suggestions will be very gratefully received!

Thanks again,

Dan.


Pan Troglodytes wrote:
> 
> Sorry Dan, my brain must not have been fully in gear.  You do need to
> check
> the columns sort order:
> 
>         if (obj1.summaryRow)
>           return col1.sortDescending ? -1 : 1
>         else if (obj2.summaryRow)
>           return col1.sortDescending ? 1 : -1
>         else if (obj1.value < obj2.value)
>           return -1
>         else if (obj1.value > obj2.value)
>           return 1
>         else
>           return 0;
> 
> Where col1 is the id of the column being sorted.  That should (hopefully)
> do
> it.
> 

-- 
View this message in context: 
http://www.nabble.com/AdvancedDataGrid%3A-Exclude-last-row-from-sorting-tp19458035p19509060.html
Sent from the FlexCoders mailing list archive at Nabble.com.

Reply via email to