I am using symfony2.6 with knp paginator bundle. On simple page It's working perfect. But When I implement pagination on page which one load by ajax call then it's not working.
So for this I implement something different with ajax call. In click on next page I sent ajax call and the rest remaining product id. That product id I am sending through ajax and get the data via query and then set again in pagination then render but Data is coming and pagination is not working.
My code is here :-
<div class="pagination">
//entities -> all products
{{ knp_pagination_render(entities) }}
<script>
var attr = product.id;
$(document).on("click",".s_p_c_pagination .pagination a",function(evt){
$('#mainCntData').css("opacity", "0.3");
$.ajax({
type: "POST",
url: $(this).attr('href'),
data:{ "attarFil" : attr },
})
.done(function( data ) {
//Result Div
});
evt.preventDefault();
});
</script>
Controller :-
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
if ($request->isXmlHttpRequest()) {
$keyword = $request->get('data');
if(!empty($keyword)){
$result = $query->getResult($keyword);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$result,
$this->get('request')->query->getInt('page', 1)/*page number*/,
10/*limit per page*/
);
return $this->render('ABCBundle:Home:index.html.twig', array('entities' => $pagination));
}else{
if($request->isMethod('POST')){
$productId = $request->get('attarFil');
$pageNo = $request->get('page');
$product = $em->getRepository('HousePlansAppBundle:Product')->findBy(array('id'=>$productId));
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$generateId,
$this->get('request')->query->getInt('page', $pageNo)/*page number*/,
10/*limit per page*/
);
return $this->render('ABCBundle:Home:index.html.twig', array('entities' => $pagination));
}
}
}
}