INFINITE SCROLLING WITH WILL PAGINATE
When we want to use the Infinite Scrolling then sometimes we are facing problem with Infinite Scrolling with Pagination.
So I am giving some steps that will try to help for that : -
Firstly we have to add the gemgem 'will_paginate', '~> 2.3.16'
Then in our controller
def show@users = User.all.paginate(:page => params[:page], :per_page => 1)
respond_to do |format|
format.js
end
end
After that in our view page
show.html.erb
=render :partial => "user_list", :locals=>{:users=>@users}_user_list.html.erb
#product_specs
%table
%tbody
%tr
%td
our content.....
#infinite-scrolling= will_paginate @users
<script type="text/javascript">
$(document).ready(function() {
if ($('.pagination').length)
{
$(window).scroll(function()
{
var url = $(".pagination a[rel='next']").attr('href');
if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50)
{
$('.pagination').show();
$('.pagination').addClass('loader-icon').html('<img src="/images/ajax-loader-small.gif"/>');
$.ajax({
url: url,
type: 'get'
});
return;
}
});
return $(window).scroll();
}
});
</script>
show.js.erb:-
$("#infinite-scrolling .pagination").replaceWith('<%= escape_javascript will_paginate(@users) %>');$('#product_specs > table > tbody:last-child').append("<%= escape_javascript(render(:partial => 'products/user_list')) %>");
$('.pagination').hide();
Comments