datagrid
datagrid copied to clipboard
DoctrineDataSource sorting on join table
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();