contributte / contributte/datagrid

DoctrineDataSource sorting on join table

Open
#654 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
296
Forks
215
PR merge metrics
No merged PRs in 30d

Description

Hi,
I have problem with sorting in DoctrineDataSource.

$qb = $this->segmentRepository->getQb();
$grid->setDataSource($qb);

$grid->addColumnText('vhCnt', 'admin.grid.segment.vehicleCount')
	->setSortable()
	->setSortableCallback(
		function (QueryBuilder $qb, $val) {
			$qb->leftJoin('q.vehicles', 'vh');
			$qb->groupBy('q.id');
			$qb->addOrderBy('COUNT(vh.id)', reset($val));
		}
	)
	->setRenderer(
		function (Segment $item) {
			return $this->segmentRepository->getVehiclesCount($item);
		}
	);

When u sort by vhCnt column, grid display only one row. Rows counter at the bottom works fine.
When you set fetchJoinCollection to false, everything works fine.
DoctrineDataSource.php:129

$iterator = (new Paginator($this->getQuery(), false))->getIterator();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at DoctrineDataSource.php:129 and reproduce the sorting callback shown in the issue, comparing Doctrine Paginator behavior with fetchJoinCollection enabled and disabled. The result should preserve all grid rows while sorting by COUNT(vh.id), with the existing rows counter still working when fetchJoinCollection is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.