Selection Lists and sorting data grids

Hello - In my app I'm displaying many data grids, and I'm trying to add multiple selection lists and a search box to each grid to allow filtering the rows. Since I'm very new to this, I'm trying to understand how to do things right from the start. Say I have product and vendor models like so:

./script/generate model Product name:string, vendor_id:integer, in_stock:boolean ./script/generate model Vendor name:string, location:string

of course, the product belongs_to :vendor and the vendor has_many :products. So far so good.

My app displays a grid of products, and I'd like to stack filter them using a selection list of vendors, and a list of in_stock. My first question is how to filter the grid with each selection. Say these are the drop down lists:

<% selection :product, :vendor_id, (Vendor.find(:all, :order => "name").collect {|v| [v.name, v.id] }).insert(0, ['--All--','all']) %>

# will generate a list of 'All', 'Vendor 1', 'Vendor 2', etc. # <select id="product_vendor_id" name="product[vendor_id]"> # <option value="all">--All--</option> # <option value="1">Vendor 1</option> # <option value="2">Vendor 2</option> # ... # </select>

<% selection :product, :in_use, [['--All--','all'],['YES', 'true'],['NO', 'false']] %>

# will generate a list of 'All', 'YES', 'NO' # <select id="product_in_stock" name="product[in_stock]"> # <option value="all">--All--</option> # <option value="true">YES</option> # <option value="false">NO</option> # </select>

1. How do I sort the table when the user selects something? I'm assuming this should be done with a call to the controller or helper, but not sure how. 2. How do I use ajax to sort without postback? 3. How do I throw in a free text search box in the mix?

I realize that's a lot of ground to cover, but even a some helpful link will be great - thanks :slight_smile:

On the same note, how would I go about turning the column headers to links that'll sort the table by the column clicked? Such that if the user click the Product Name header, the table sorts alphabetically by product name.

Thanks again.