datagrid icon indicating copy to clipboard operation
datagrid copied to clipboard

DoctrineDataSource sorting on join table

Open MartinSzollos2016 opened this issue 7 years ago • 0 comments
trafficstars

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

MartinSzollos2016 avatar Apr 28 '18 08:04 MartinSzollos2016