Skip navigation
Currently Being Moderated

DataGrid secondary sort?

Aug 20, 2013 2:30 PM

I'm using a Spark DataGrid and having a hard time figuring out how I can make the sorting apply secondary sort fields. For example, consider this data set:

 

Name(String) | Value(Number)

 

Alfa | 1

Bravo | 1

Charlie | 1

Delta | 1

 

If the user sorts on Value, I want the Name to be sorting alphabetically (asc/desc is not critical) -- right now it comes out quite randomly.

 

I also want this to work with BOTH user initiated header-sort clicks AND programmatically setting the sort based on a primary sort field and order input.

 

What's the best way to go about doing this?

 

My fail attempts include (I listen for SORT_CHANGE for user sorting and re-apply a sort which includes secondary columns):

 

1. Using sortByColumns() -- this had multiple issues I couldn't work around: sort order seems to be reversed from what you specify if the column is already being sorted, and it would display arrows on ALL headers, not just the primary sort header.

2. Setting the .sort property on the dataProvider ArrayCollection -- this *almost* worked, it just doesn't show the sort arrow indicator in the header when applied programatically. Is there a way to fix this?

 

Or is there a more straight-forward way?

 

Thanks!

-Aaron

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points