Index: lib/will_paginate/view_helpers.rb =================================================================== --- lib/will_paginate/view_helpers.rb (révision 300) +++ lib/will_paginate/view_helpers.rb (copie de travail) @@ -17,7 +17,9 @@ :inner_window => 4, # links around the current page :outer_window => 1, # links around beginning and end :separator => ' ', # single space is friendly to spiders and non-graphic browsers - :param_name => :page + :param_name => :page, + :remote_options => {}, + :remote_html_options => {} } mattr_reader :pagination_options @@ -33,6 +35,8 @@ # outer_window: how many links are around the first and the last page, defaults to 1 # separator: string separator for page HTML elements, default " " (single space) # param_name: parameter name for page number in URLs, defaults to "page" + # remote_options: options for link_to_remote. If not empty you get a link_to_remote with these options instead of the classic link. default is empty. + # remote_html_options: html_options for link_to_remote, default is empty. # # All extra options are passed to the generated container DIV, so eventually # they become its HTML attributes. @@ -44,7 +48,10 @@ page = entries.current_page options = options.symbolize_keys.reverse_merge(pagination_options) inner_window, outer_window = options.delete(:inner_window).to_i, options.delete(:outer_window).to_i - param = options.delete :param_name + param = Hash.new + param[:param_name] = options.delete :param_name + param[:remote_options] = options.delete :remote_options + param[:remote_html_options] = options.delete :remote_html_options min = page - inner_window max = page + inner_window @@ -85,7 +92,23 @@ content_tag :span, text, :class => span_class else # page links should preserve GET parameters, so we merge params - link_to text, params.merge(param.to_sym => (page !=1 ? page : nil)) + if param[:remote_options].empty? + link_to text, params.merge(param[:param_name].to_sym => (page !=1 ? page : nil)) + else + # Merge params and put page number even if page is 1. So if you have multiple ajax will_paginate on the + # same action, you know which one you have to render, ex : + # format.js { + # if params[:page_line_items] + # render :partial => "line_items" + # elsif params[:page_packages] + # render :partial => "packages" + # end + # } + param[:remote_options][:url] = {:params => params.merge(param[:param_name].to_sym => page)} + # If javascript is disabled, you'll still have your pagination working + param[:remote_html_options][:href] = url_for(params.merge(param[:param_name].to_sym => (page !=1 ? page : nil))) + link_to_remote text, param[:remote_options], param[:remote_html_options] + end end end end Index: README =================================================================== --- README (révision 300) +++ README (copie de travail) @@ -62,7 +62,18 @@
Now let's render us some pagination!
<%= will_paginate @posts %> +Here is an example for will paginate with ajax calls + <%= will_paginate @posts,{ + :param_name => 'page_posts', + :remote_options => { + :method => :get, + :update => "div_posts", + :before => "Element.show('busy_paginate')", + :success => "Element.hide('busy_paginate')" + } + } %> + == Authors, credits Ruby port by: PJ Hyett, Mislav Marohnić (Sulien)