开发者

will_paginate + jquery ui tabs

HI,

I'm using a jquery ui modal dialog. In this dialog i have two jquery ui tabs, 开发者_StackOverflow中文版each tabs contain a div with a list of items which are paginated with will_paginate(rails).

I have several issues :

  • when I click on a page of the pagination my modal is closed, but i have the url/?page=2
  • when I reopen the modal i am on the second page of my first tab, and if I click on the second tab I'm also on the second page, which is not wanted

Thx for your help.


I assume your modal dialog is closing because you are refreshing the page with the new parameter. Here are the official instructions for using ajax with will_paginate so you don't need to refresh the page:
https://github.com/mislav/will_paginate/wiki/Ajax-pagination

You can also try the RemoteLinkRenderer solution if you don't care about the crawlability of these pages. Basically, create a helper called remote_link_renderer.rb and put in it:

class RemoteLinkRenderer < WillPaginate::LinkRenderer
  def prepare(collection, options, template)
    @remote = options.delete(:remote) || {}
    super
  end

  protected
  def page_link(page, text, attributes = {})
    @template.link_to_remote(text, {:url => url_for(page), :method => :get}.merge(@remote), attributes)
  end
end

Then in your view, make sure your will_paginate call has the following options:

<%= will_paginate @items, :renderer => 'RemoteLinkRenderer' , :remote => { :update => 'items_div'} %>

where @items is whatever your paginated variable is and items_div is the id of the dom element being updated.

You can google for will_paginate remotelinkrenderer for more info.

As for your second issure, the problem is that both paginations are using the same paramter for keeping track of which page they're on. You can fix this by, in the view when calling will_paginate, including the :param_name option on one or both instance, e.g.:param_name=>:tab2_page. Specified here: http://rubydoc.info/gems/will_paginate/2.3.15/WillPaginate/ViewHelpers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜