I have a search page that allows the user to search on many different fields. After clicking search the page displays 10 entries per page by default, with the option to view the next 10, or pick a page number, using will_paginate. There is a drop down menu that allows you to pick how many entries the user sees per page.
I have tried two pieces of code:
Results per page: <%= select_tag :per_page, options_for_select([10,20,50], :selected=>params[:per_page]), { :onchange => "this.form.submit();"} %></br>
and
Results per page: <%= select_tag :per_page, options_for_select([10,20,50], :selected=>params[:per_page]), :onchange => "'#{request.query_string}&per_page=' + this.getValue()" %></br>
When the first drop down is changed to 20 for example, the page instantly searches again, but displays the results 20 per page.
The second drop down allows you to select a entry per page number, but to change the view, you have to re click search.
I want my code to work more like the first drop down, but I think re searching is a bit expensive. Is there a way to stop resubmitting the search but change the display?
Thanks in advance
If you change the amount of items displayed per page, a requery has to be done anyway (because only the items to display have been loaded from the database). And if you change the items displayed per page, and you are on page 2, what will you see? Items 10 – 60? So if you change the items per page, you almost always also switch to page one, and that requires a requery anyway.
And second: it seems you want to reload the data in the javascript. You do a call to get the data, but seem to do nothing with the loaded data.