Radiobutton onclick


#1

Hi,

I would like to make a simple html which displays the contents of a
table from a database. So I put radiobuttons near the titles of the
columns to note and do a sorting by that column. But I don’t know how
to implement that the clicking on one of the radiobuttons make the
sorting. The problem is the view part. How to give a radiobutton to
make some action on a click by the helper?

The code is:


<% for col in Product.content_columns %> <% end%> <% for prod in @product %> <% for col in Product.content_columns %> <% end %> <% end %>
<%= radio_button :index, 'head', col.name %><%= col.name %>
<%= prod.send(col.name) unless (prod.send(col.name).to_s == "") %> <%= " " if (prod.send(col.name).to_s == "") %>
-----

Thanks.

Abbath


#2

Abbath wrote:

Hi,

I would like to make a simple html which displays the contents of a
table from a database. So I put radiobuttons near the titles of the
columns to note and do a sorting by that column. But I don’t know how
to implement that the clicking on one of the radiobuttons make the
sorting. The problem is the view part. How to give a radiobutton to
make some action on a click by the helper?

Another approach you can use that avoids radio buttons would be to make
the title of each column a hyperlink with a ‘sort’ param.

<%= link_to ‘Column1’, :action=>‘list’, :sort=>‘column1’ %>

Then have the ‘list’ action pick up the ‘sort’ param and use that in
your find or paginate ( :order => :sort, I think).

This basically forces the database to return the results in the sorted
order and then re-displays it.

There are a bunch of AJAXy ways to do the same thing that look nicer,
but this is an easy solution.

_Kevin

disclaimer… this was all out of my head, so some of the coding may
need to be tweaked.


#3

On 12/30/05, Kevin O. removed_email_address@domain.invalid wrote:

Another approach you can use that avoids radio buttons would be to make
There are a bunch of AJAXy ways to do the same thing that look nicer,
but this is an easy solution.

_Kevin

disclaimer… this was all out of my head, so some of the coding may
need to be tweaked.

Kevin, I was lurking on the your answer. It will make my app more
usefull. Thanks.

FYI – :order => :sort is actually :order => params[:sort]

Thanks again,
Greg

Greg F.
The Norcross Group
Forensics for the 21st Century