protected function countTotalRows()
    {
        $source = $this->getSource();
        /** @var \Doctrine\ORM\Query\Expr\Select $select */
        $source->resetDQLPart('select')->setFirstResult(0)->select('count(' . $this->entityAlias . ')');
        return (int)$source->getQuery()->getSingleScalarResult();
    }