Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Ajax Support

#67

Here is a first patch which adds Ajax calls to Will Paginate.

It can be very useful if you have a lots of models with pagination in the same page. You will only update one at the time ( and you can put effects between each pages ;)

Be careful, you have to put the will_paginate call inside the element you want to update in order to also update the pagination control. Maybe, i'll improve this later ( or maybe you can already do it outside with RJS but I haven't tried )

Example usage:

In your controller :

@posts = Post.paginate :page => params[:page_posts], :per_page => 10

In your view :

    <% for post in @posts -%>

  1. Render `post` in some nice way.
  2. <% end -%>

Now let's render us some pagination!

<%= will_paginate @posts,{

:param_name => 'page_posts',

:remote_options => {

:method => :get,

:update => "div_posts",

:before => "Element.show('busy_paginate')",

:success => "Element.hide('busy_paginate')"

}

} %>

Reported by Florent Piteau · July 18th, 2007 @ 03:11 AM

State: invalid
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Chris Wanstrath
    Chris Wanstrath
    • State changed from new to open
    • Assigned user changed from Chris Wanstrath to Mislav

    July 18th, 2007 @ 03:11 AM

  2. Matt Aimonetti (mattetti)
    Matt Aimonetti (mattetti)

    I don't think the plugin itself should handle any ajax calls.

    simply use unobtrusive javascript and you can achieve the same result in less than 5 minutes without hacking anything ;)

    http://railsontherun.com/2007/9/...

    And I'm pretty sure you can probably do the same with Prototype only, Mislav?

    -Matt

    September 28th, 2007 @ 09:52 PM

  3. Mislav
    Mislav
    • State changed from open to invalid
    • Title changed from [Will Paginate][Patch] Ajax Support to Ajax Support

    I agree with Matt. I kept this open to give me time to think in what way could I help Ajax pagination ... I realized that the user is on his own, because I'm definitely not generating JavaScript in the view (I know that Rails does, but I don't).

    September 29th, 2007 @ 10:21 AM

  4. Ayyanar
  5. Ayyanar
    Ayyanar

    Hi, I updated my views_helper.rb with the lines from will_paginate_with_ajax_calls.diff. Iam not able to get the pagination working. So many errors. I attached my view_helpers.rb. Plz let me know where Iam missing.

    December 16th, 2007 @ 09:41 PM

  6. Tom
    Tom

    The lowpro.js approach works great if you only have one pagination area on a page. But I have a couple of cases where I'd like to have more than one paginator on the page which would need to be handled via different actions. And will_paginate uses the params from the current template to generate the URL used by the paginator. So I am stuck with one action for all paginators and no way to differentiate between them.

    Can you give us a way to override the URL used to create the links in will_paginator?

    December 13th, 2007 @ 05:41 PM

  7. bdoyle
    bdoyle

    @Tom

    I had this same problem and I modified the will paginate code to take a url in the options and it's working great. In my template file I do something like:

    <%= will_paginate @guides, :url => {:action => 'show_guides', :login => params[:login] }, :class => 'author_guides' %>

    I had to make a slight change in the LinkRenderer#page_link_or_span method:

    def page_link_or_span(page, span_class, text)

    unless page

    @template.content_tag :span, text, :class => span_class

    else

    1. page links should preserve GET/POST parameters

    if @options[:url]

    @options[:url][:page] = page

    @template.link_to text, @options[:url]

    else

    @template.link_to text, @template.params.merge(param => page != 1 ? page : nil)

    end

    end

    end

    December 13th, 2007 @ 06:44 PM

  8. Aketzu
    Aketzu

    I solved it with little patch to LinkRenderer.page_link_or_span()

        def page_link_or_span(page, span_class, text = nil)
          text ||= page.to_s
          classnames = Array[*span_class]
    
          if page and page != current_page
            if @options[:update] then
              @template.link_to_remote text, {:url => url_for(page), :method => :get, :update => @options[:update]}, {:rel => rel_value(page), :class => classnames[1] }
            else
              @template.link_to text, url_for(page), :rel => rel_value(page), :class => classnames[1]
            end
          else
          @template.content_tag :span, text, :class => classnames.join(' ')
          end
        end
    

    and then just use <%= will_paginate @permits, :update => :entries %>

    May 21st, 2008 @ 07:57 AM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.