Skip to content

Instantly share code, notes, and snippets.

@guilu
Created September 10, 2014 20:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save guilu/2e8138773d6b7435548a to your computer and use it in GitHub Desktop.
Save guilu/2e8138773d6b7435548a to your computer and use it in GitHub Desktop.
infinte scroll knppaginatorbundle twig
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>infinite scroll</title>
</head>
<body>
{% block body %}
<!-- aqui pones el la plantilla que pinta los resultados de knppaginator -->
{% include 'plantilla_knppaginatorbundle_resultados.html.twig' with {'pagination': pagination} %}
<div id='more' style="display: none;color:#ccc"><h3>Loading...</h3></div>
<div id='no-more' style="display: none;color:#ccc"><h3>No more results</h3></div>
{% endblock %}
<script type="text/javascript">
$(document).ready(function(){
//se supone que la primera ya se ha cargado, vamos por la 2 en adelante
var page = 2;
var total = {{ pagination.getTotalItemCount }};
var itemsPerPage = {{ pagination.getItemNumberPerPage }};
$(window).scroll(function () {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
var data = {
"page": page++
};
console.log(data);
if((page-1)* itemsPerPage > total) {
$('#no-more').show();
}else{
$('#more').show();
$.ajax({
type: "GET",
url: "{{ path('current_pagina') }}",
data:data,
success: function(data) {
$('#more').hide();
$('#destacados').append(data);
}
});
}
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment