-
Notifications
You must be signed in to change notification settings - Fork 3
SortingWishlist
bigfleet edited this page Sep 12, 2010
·
6 revisions
You shouldn’t have to define something in the to_sort block to have it take effect, but it’ll be the simple one by default.
IMPLEMENTED
data_table(:users) do |table|
table.sort_spec do |sort|
sort.default :name, :desc
end
end
The first time this data_table is loaded, if there are no other parameters concerning sorting, the default will be used.
IMPLEMENTED
to_sort do |sort|
sort.option :album_count, :desc
end
This invocation stores descending order as the preferred order for the sort. The first time that column is sorted, it will be in descending order.
data_table(:albums) do |table|
table.sort_spec do |sort|
sort.option "Length", :length_in_seconds, :desc, :from => :songs
end
end
This sort should rely on the finder to conjure the appropriate join or include, and should generate ‘songs.length_in_seconds’ as the default sort option. This also works for disambiguation if two different tables have a field named the same thing. This should be available on a per-option basis, with a default for all options.
- Tags are often on polymorphic taggables—a tag listing should be able to sort based on some potentially shared elements of the polymorphism (STI, for example, would have plenty.)
- Envision a LineItem model with an optional buyer review model. You ought to be able to sort by that rating, even though the user perhaps did not supply one. This is probably something that needs to be taken care of in the finder, but there could possibly be a data_table responsibility in there somewhere.