-
-
Save pije76/0d3888c9e5955963ff80da4f5e86cc80 to your computer and use it in GitHub Desktop.
infinte scroll knppaginatorbundle twig
This file contains hidden or 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
<!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