SortHelper combined columns

18 views
Skip to first unread message

Zdravko Balorda

unread,
Nov 13, 2014, 10:32:35 AM11/13/14
to rubyonra...@googlegroups.com
Hi,
I'd like to sort table of patiens with lastname, firstname in the same
column.
Of course in the model Patient there are two columns, which I need
joined while sortable.
Is there any way to do that with SortHelper?

Regards, Zdravko

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Nov 13, 2014, 10:41:48 AM11/13/14
to rubyonra...@googlegroups.com
On 13 November 2014 15:30, Zdravko Balorda <li...@ruby-forum.com> wrote:
> Hi,
> I'd like to sort table of patiens with lastname, firstname in the same
> column.
> Of course in the model Patient there are two columns, which I need
> joined while sortable.
> Is there any way to do that with SortHelper?

Can you be more explicit in what you want to sort on? Do you want to
sort by lastname and then within those with the same lastname then
sort by firstname? If so then just specify something like
@patients.order(:lastname, :firstname)

Colin

Zdravko Balorda

unread,
Nov 13, 2014, 12:36:51 PM11/13/14
to rubyonra...@googlegroups.com
I use SortHelper which provides for sorting by any column of the table.
With patient name I would like to have only one column. The combined
column could be 'name' as in:
select ..., lastname||', '||firstname as name from patients... order by
name

This column does not appear in the table itself. It is concatenated
column. Ordering by name would also provide for correct ordering. Can I
fool SortHelper to use such a fake column (not in the model) to work
with?

Colin Law

unread,
Nov 13, 2014, 12:49:25 PM11/13/14
to rubyonra...@googlegroups.com
No idea as I don't know what SortHelper is, and a quick google
revealed nothing that looked in any way current. Why would you not
want to do this the most efficient way which is likely to be when
fetching from the database?

Note that if you just concatenate the columns you will be unlikely to
get what you want, as you need it to sort on lastname then firstname,
which may not be the case if you just concatenate the strings.

Colin

>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b7d3c6442bf4e43a6a976ffbfaf7af45%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages