How to add pagination inside a bootstrap modal

2019-09-08 19:21发布

I have a user's list, when click on 'show activities' this shows a list of user activities in a modal from partial file _user_activities.html.haml. This activities list is a paginated view. I want to add pagination only for this activities alone inside my modal window. How to do this? I am already using will_paginate, that makes my page to reload. How to achieve this?

users/index.html.haml

%table
  %thead
    %th Name
    %th Actions
  %tbody
    - @users.each do |user|
      %tr
        %td= user.name
        %td
          %i.icon-play
          %div.modal.hide
            = render 'user_activities', user: user

= will_paginate users

:javascript
  $('i').click(function() {
    $(this).next(.modal).modal('show');
  });

users/_user_activities.html.haml

%table
  %thead
    %th Name
    %td Type
  %tbody
    - user.activities.eadch do |activity|
      %tr
        %td= activity.name
        %td= activity.type

= will_paginate user.activities

2条回答
地球回转人心会变
2楼-- · 2019-09-08 20:03

You can use kamiray or will_paginate gem very easy to use have a look at following example using will paginate,

do this in your controller and it will add pagination.

@set = SomeObject.paginate(:page       => params[:page],
                           :per_page   => 20,
                           :order      => 'created_at DESC',
                           :conditions => { :foo => 'bar' })

here is a railscast for Kaminary and willpaginate Hope it would solve your problem.

查看更多
狗以群分
3楼-- · 2019-09-08 20:04

One way to achieve the ajax type pagination is with Kaminary gem. We can easily set up the pagination with Kaminary. I don't know how to achieve the ajax type pagination with will_paginate, but i used kaminary in my one of project and its quite easy with this.

update

Check How to Implement ajax pagination with will_paginate gem for providing the ajax type pagination with will_paginate.

查看更多
登录 后发表回答