Kreyu/data-table-bundle

Table Paginator shows double the expected results on the final page

Closed this issue · 4 comments

Something's up with the pagination code, I think something in DoctrineOrmResultSetFactory 's getPaginatorItems isn't quite right:

Worked basic example:

// controller
$table = $this->createDataTable(
  TestTableType::class,
  $repo->getTestQuery(),
);
$table->handleRequest($request);

return $this->render('test.html.twig', [
  'table' => $table->createView(),
]);

// repository
public function getTestQuery(): QueryBuilder
{
    $qb = $this->createQueryBuilder('entity');
    return $qb;
}

// table
class TestTableType extends AbstractDataTableType
{
    public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
    {
        $builder
            ->setDefaultPaginationData(new PaginationData(
                page: 1,
                perPage: 10,
            ))
            ->addColumn('moduleCode', TextColumnType::class, [
                'sort' => true,
            ]);
    }
}

/test?page_test_table=1
Correctly shows number of pages and item count
image

Penultimate page /test?page_test_table=31 shows correctly too
image

Last page /test?page_test_table=32 returns too many results
image

Doctrine shows a second query being run on the last page:
image

Thanks for the bug report! I noticed this issue in one of my projects yesterday, but had no time to debug it properly. I think you're right, the result set factory seems to be the cause. I'll try to fix it asap when I'm on my work computer tomorrow :)

Thanks for the update :) I would've worked on a fix + PR if I had more time to investigate!

Hey @kris-sum, this issue should be fixed in the 0.17.11 version, can you please confirm it is working in your project?

Looks great! Thank you for the speedy response