Sort order in edit view

0 views
Skip to first unread message

SteveG

unread,
Dec 12, 2008, 7:17:01 PM12/12/08
to Streamlined
Hello all. Started playing with streamlined today and so far so good
except this one issue. I have a simple model. An artist can have
multiple Albums. When I am looking at the list of Albums I click Edit
to change the Artist and drop comes up correctly listing the artists.
I want that select box to be ordered by artist.name and I cannot
figure how to do it. I found out how to list the artists and albums in
list view by using the default_order_options option.

Thanks,
Steve

Bonefish

unread,
Dec 12, 2008, 8:58:24 PM12/12/08
to Streamlined
Hi Steve,

Use :options_for_select and do your sorting in the custom method.

http://www.streamlinedframework.org/wiki/ColumnOptions

Regards,
Kerry

SteveG

unread,
Dec 13, 2008, 1:49:28 AM12/13/08
to Streamlined
Thanks Kerry.

SteveG

unread,
Dec 13, 2008, 12:37:46 PM12/13/08
to Streamlined
Kerry, that worked fine when I am editing the entire Album record but
I still cannot get it to sort when I do the inline edit of the Artists
on the list view. I should note that this is a many to many
relationship (Album has many Artists and an Artist has many Albums)

Here is my configuration for Album


Streamlined.ui_for(Album) do

user_columns :name,



:artists, {
:options_for_select => :custom_options_method,
:show_view => [
:list,
{:fields => [:name]}
]
},
:munged_name, {:read_only=>true},
:type, {:read_only=>true},
:year_released,
:tags,
:distributor,
:rating,
:created_at

edit_columns :name, :artists, {:options_for_select
=> :custom_options_method}, :year_released, :distributor
default_order_options :order => "name"


end

Bonefish

unread,
Dec 14, 2008, 2:12:18 PM12/14/08
to Streamlined
Hi Steve,

What does your :custom_options_method look like? Where did you put it?

Regards,
Kerry

SteveG

unread,
Dec 15, 2008, 10:35:39 AM12/15/08
to Streamlined
Kerry, I stepped through the code and, unless I missed something, it
looks like streamlined does not support this functionality for the
inline editing of the relationship. Its works fine the Edit View
though using the :custom_options_method.

The issue seems to lie in the
Streamlined::Controller::RelationshipMethods module. If you look at
the set_items_and_all_items it just does a @klass.find(:all).

I quickly wrote proof-of-concept plugin the adds an :order_by method
to the Streamlined::Column::Association class and aliased
set_items_and_all_items to use the order_by method. I also modified
the Association.items_for_select method so it also supports the
order_by method. I did that because I would think in cases where the
default query works for you, the only other functionality you would
need is to controller the ordering of the columns.

If anyone is interested I can post it here. I was also thinking of
submitting as a patch because it is really only a few lines of code.

Bonefish

unread,
Dec 15, 2008, 1:13:10 PM12/15/08
to Streamlined
Hi Steve,
Thanks for the looking into this and providing feedback. It seems like
you've found a good solution to a common issue.

>>submitting as a patch because it is really only a few lines of code.
That would be great.

Regards,
Kerry
Reply all
Reply to author
Forward
0 new messages