Glad you got the result you were looking for. Yes, it does kind of suck
that they made the sorting method so simple. The problem is that that part
of the code isn't grid code, it's ICollectionView code. It winds up using
SortFields, which are very unaware of any griddish concerns. It's a great
way to do it, from a code design point of view. But sometimes it can throw
a monkey wrench into practical applications.
On Tue, Sep 16, 2008 at 8:06 AM, DanMurray <[EMAIL PROTECTED]> wrote:
>
> Hi Jason,
>
> I think I have this working as required now with just the one sort method
> used by every column (I think this is OK as I have multi-column sorting
> turned off).
>
> I have moved the createColumns() method onto the MyAdvancedDataGrid class
> and added the following to that class:
>
> // map of column objects keyed against their datafields (populated by
> createColumns() method)
> private var mColumns:Object;
> // keep track of currently sorted column
> private var mSortedColumn:AdvancedDataGridColumn;
>
> public function MyAdvancedDataGrid (id:String)
> {
> <snip>
> addEventListener(AdvancedDataGridEvent.SORT, sortEventHandler);
> }
>
> private function sortEventHandler(event:AdvancedDataGridEvent):void
> {
> mSortedColumn = mColumns[event.dataField];
> }
>
> Then within createColumns() every new column gets
>
> column.sortCompareFunction = compareExcludeSummaryRow;
>
> where the sort method is:
>
> private function compareExcludeSummaryRow(obj1:Object, obj2:Object):int
> {
> // should never be in this state
> if (mSortedColumn == null)
> {
> // TODO log error
> return 0;
> }
>
> var isSortDescending:Boolean = mSortedColumn .sortDescending;
> var sortField:String = mSortedColumn .dataField;
>
> if (obj1.summary)
> {
> return isSortDescending ? -1 : 1;
> }
> else if (obj2.summary)
> {
> return isSortDescending ? 1 : -1;
> }
> else if (obj1[sortField] < obj2[sortField])
> {
> return -1;
> }
> else if (obj1[sortField] > obj2[sortField])
>
> {
> return 1;
> }
> else
> {
> return 0;
> }
> }
>
> This seems to work nicely now, but as I say I think it is restricted to
> single column sorting, which is fine for me.
>
> Thanks for your help, and any further comments appreciated!
>
> 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-tp19458035p19511454.html
> Sent from the FlexCoders mailing list archive at Nabble.com.
>
>
>
--
Jason