Created
December 1, 2010 23:56
-
-
Save Erol/724480 to your computer and use it in GitHub Desktop.
Progressive AJAX Pagination for Mislav's WillPaginate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="table"> | |
... | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initAJAXPagination(selector){ | |
$(selector).click(function(event){ | |
$.ajax({ | |
type: 'GET', | |
url: $(this).attr('href'), | |
dataType: 'script' | |
}); | |
event.preventDefault(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(function(){ | |
initAJAXPagination('#table div.pagination a'); | |
}); | |
</script> | |
<%= render :partial => 'table' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#table').replaceWith('<%= escape_javascript(render :partial => 'table', :layout => false) %>') | |
initAJAXPagination('#table div.pagination a'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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