Skip to content

Instantly share code, notes, and snippets.

@Erol
Created December 1, 2010 23:56
Show Gist options
  • Save Erol/724480 to your computer and use it in GitHub Desktop.
Save Erol/724480 to your computer and use it in GitHub Desktop.
Progressive AJAX Pagination for Mislav's WillPaginate
<div id="table">
...
</div>
function initAJAXPagination(selector){
$(selector).click(function(event){
$.ajax({
type: 'GET',
url: $(this).attr('href'),
dataType: 'script'
});
event.preventDefault();
});
}
<script>
$(function(){
initAJAXPagination('#table div.pagination a');
});
</script>
<%= render :partial => 'table' %>
$('#table').replaceWith('<%= escape_javascript(render :partial => 'table', :layout => false) %>')
initAJAXPagination('#table div.pagination a');
class ResourcesController < ApplicationController
def index
@resources = Resource.all.paginate(:page = params[:page])
respond_to do |wants|
wants.js { render :layout => false }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment