I have a blog.Few articles inside.Per each article I have a lot of comments that I decide to paginate in group of 5 (let's say..if i have 15 comments i have 3 pagination buttons).
I did this by a method of my comment_manager class on pageLoad.
public function pagination($in_art,$perPage)
{
$per_page=$perPage;
$count=$this->countComments($in_art);
$pages = ceil($count/$per_page);
if($count>=$perPage)
{
echo"<div class='pagination'>";
for($i=1; $i<=$pages; $i++)
{
echo "<div class='pag' id='pag_{$i}'>$i</div>";
}
echo"</div>";
}
}
everything is fine.
This is how I handle my buttons through JQuery
$(document).ready(function()
{
[...]//code missing for sake of brevity
$('#pag_1').css({'color' : '#FF0084'}).css({'border' : 'none'});
//Pagination Click
$(".pag").click(function(){
//CSS Styles
$(".pag")
.css({'border' : 'solid #dddddd 1px'})
.css({'color' : '#0063DC'});
$(this)
.css({'color' : '#FF0084'})
.css({'border' : 'none'});
//Loading Data
var data="page="+pageNum+"&id_art="+idArt;
$.ajax({
type: "POST",
url: "php/pagination_data.php",
data: data,
cache: false,
success: function(html){
$('#comments_'+idArt).html(html);
}
});
});
The point is I need to refresh my pagination buttons after deleting or adding new comments on the fly (dont want the whole page to refresh!).So remove them or add new ones if needed(for example with 16 comments i need one more button)
Thanks
Luca