APYDataGridBundle
APYDataGridBundle copied to clipboard
How to integrate KnpPaginator in my grid?
Hello! How to integrate KnpPaginator instead of default pagination apydatagrid? Maybe someone do this? Help please)
Same question.
Why closed? 👎
@Bubelbub original opener has closed this, don't know why. However I've talked with @hmert that said that bundle, in this version, is pretty stable so new features will be started only in new version (but don't ask me what these features are and when a new version will be released).
Only active work is being in progress now, is to write tests before move on and I'm doing it in my little spare free time.
Hmm ok @DonCallisto I understand. Thats no problem. I wrote my own twig extension with this function.
public function getKnpPaginatorForGrid(Grid $grid)
{
/** @var \Twig_Environment $twig */
$twig = $this->container->get('twig');
/** @var \Knp\Component\Pager\Paginator $paginator */
$paginator = $this->container->get('knp_paginator');
$url = $this->getGridUrl('page', $grid, '');
$routeGenerator = function ($page) use ($url) {
return sprintf('%s%d', $url, $page - 1);
};
return $twig->createTemplate('{{ knp_pagination_render(pagination) }}')->render([
'pagination' => $paginator->paginate(array_fill(0, $grid->getTotalCount(), null), $grid->getPage() + 1, $grid->getLimit())
]);
}
Ok it works... 95% 😅 I have a problem with the routing.
https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/doc/templates.md#setting-a-route-and-query-parameters-to-use-for-pagination-urls
I can set a route which is used for pagination. But I can't set a url.
So how I can combine the \APY\DataGridBundle\Twig\DataGridExtension::getGridUrl
with the setUsedRoute
? hmmm 🤔
I'll find it out hopefully 😎
Or somebody of you know how to solve.
Because then it'll work.
I tested it and it is rendered correct. Only if I click on a page it only reloads with ?page=2
in url.