jquery endless page in rails 3 with will_paginate
Does any one know how i can go about endless page with开发者_开发百科 jquery and will_paginate in rails 3? I have tried so many ways but it has never worked for me.
See Railscast #114 Endless Page
You should be able to make it work with Rails 3 with minimal modifications (if any).
Your endless-page.js file will look something like this
var currentPage = 1;
var autoloading = false;
if( total_number_of_paginaion_pages > 1) {
autoloading = true;
}
function checkScroll() {
if (autoloading && nearBottomOfPage()) {
currentPage ++;
autoloading = false;
$.ajax( {
url: window.location,
data: 'page=' + currentPage,
beforeSend: function() {
$('.loading-info').show()
},
complete: function(){
$('.loading-info').hide()
},
success: function(data){
eval(data);
}
});
}
}
function nearBottomOfPage() {
return scrollDistanceFromBottom() < 150;
}
function scrollDistanceFromBottom(argument) {
return $(document).height() - ($(window).height() + $(window).scrollTop());
}
$(window).bind('scroll', function (){
checkScroll();
});
And in your js.erb file will look something like this
$('.results-center').append('<%=escape_javascript(render :partial => '/search/search_result') %>');
if(! pagination_last_page) {
autoloading = true;
}
the best option for implementing endless pagination will be using will_paginate / kaminari gem with jquery.
there is a good blog on how to implement endless page and hopefully will answer your question.have a look
http://www.idyllic-software.com/blog/endless-page-using-jquery-and-will_paginate/
精彩评论