Reputation:
How can I use two paginations inside one page and make them work separately? For example, see the image below:
On the top of the image are two paginations: 1st on the left and the 2nd on the right. If I click on the 1st pagination, then I only need the data on the 1st pagination to load without the whole page being loaded; the 2nd one should stay the same and be separated.
Below is my controller code for the data shown:
@first= Post.paginate(page: params[:page], :per_page => 4).order('post_id DESC')
@second= Post.paginate(page: params[:page], :per_page => 4).order('post_id ASC')
Pagination will_paginate
Upvotes: 0
Views: 595
Reputation: 7777
For separate loading you change your paginate params like params[:page]
change to params[:first]
second is same procedure & use your view page <%= will_paginate @first, :param_name => 'first or second' %>
& then you try ajax page loading script for show result without whole page loading. you need create index.js.erb
file inside your current page folder. this tutorial very nicely described Pagination with AJAX
Hope will help you
Upvotes: 2
Reputation: 2183
You have to set separate params name( instead one page
) for two section using
<%= will_paginate @first, :param_name => 'first' %>
<%= will_paginate @second, :param_name => 'second' %>
and on your controller you can write
@first= Post.paginate(page: params[:first], :per_page => 4).order('post_id DESC')
@second= Post.paginate(page: params[:second], :per_page => 4).order('post_id ASC')
You can see will_paginate documentation
Upvotes: 0