0

我正在使用 symfony2.6 和 knp 分页器包。在简单的页面上它工作得很好。但是,当我在通过 ajax 调用加载的页面上实现分页时,它就不起作用了。

所以为此我用ajax调用实现了一些不同的东西。在单击下一页时,我发送了 ajax 调用和其余剩余的产品 ID。我通过 ajax 发送的那个产品 ID 并通过查询获取数据,然后在分页中再次设置,然后渲染,但数据即将到来,分页不起作用。

我的代码在这里:-

        <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>

控制器 :-

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));
                }
            }
    }

}
4

0 回答 0