How to add pagination inside a bootstrap modal

徘徊边缘 提交于 2019-12-13 04:59:51

问题


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

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/15631851/how-to-add-pagination-inside-a-bootstrap-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!