views:

311

answers:

0

Hi everybody, I am new to AJAX and jQuery so please excuse me if this is kind of basic:

I implemented the great jgrid by 2dconcepts (http://www.2dconcept.com/jquery-grid-rails-plugin). Now I would like to select the data in my table with the checkbox, - get the product ids (that works fine I see the alert from the 'handleSelection') and pass it over to my custom action in the rails controller to edit the specified records (very similar to Ryan B's railscast #165). I simply have no idea how I would do that.

<script type="text/javascript">
function handleSelection(id) {
alert('Open those up?:'+id);    
}
</script>


<% title "JGRID Table" %>
<%= jqgrid("Products", "products", "/products",
[
    { :field => "id", :label => "ID", :width => 40, :resizable => false },
    { :field => "vendorname", :width => 200, :label => "vendorname", :editable => true },
    { :field => "productname", :width => 230, :label => "productname", :editable => true },
    { :field => "metakeyword", :width => 250, :label => "metakeyword", :editable => true },
    { :field => "status", :width => 100, :label => "status", :editable => true, :edittype => "select", 
        :editoptions => { :value => [["inbox","inbox"], ["todo", "todo"], ["final","final"]] } },
    { :field => "category_id", :label => "category_id", :width => 100, :resizable => false, :editable => true }
],
{ :add => true, 
    :edit => true, 
    :inline_edit => true, 
    :delete => true, 
    :edit_url => "/products/post_data",
    :rows_per_page => 30,
    :height => 270,
    :selection_handler => "handleSelection", 
    :multi_selection => true }
)%>

I think I need to put the post-request in the function and call it with something like this:

<%= button_to_function('EDIT CHECKED', 'handleSelection(id)', {
:id => "products_select_button"}) %>

But to be honest, not even that button would work, as it passes the string "products_select_button" to the function, and not the collected value...

Your help is greatly appreciated!

Val

<%= button_to_function('EDIT CHECKED', 'handleSelection(id)', {:id => "products_select_button"}) %>