Grid/Source/Document.php
public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION)
    {
        $this->query = $this->getQueryBuilder();

        $validColumns = [];
        foreach ($columns as $column) {

            //checks if exists '.' notation on referenced columns and build query if it's filtered
            $subColumn = explode('.', $column->getId());
            if (count($subColumn) > 1 && isset($this->referencedMappings[$subColumn[0]])) {
                $this->addReferencedColumnn($subColumn, $column);

                continue;
            }

            $this->query->select($column->getField());

            if ($column->isSorted()) {
                $this->query->sort($column->getField(), $column->getOrder());
            }

            if ($column->isPrimary()) {
                $column->setFilterable(false);
            } elseif ($column->isFiltered()) {
                // Some attributes of the column can be changed in this function
                $filters = $column->getFilters('document');

                foreach ($filters as $filter) {
                    //normalize values
                    $operator = $this->normalizeOperator($filter->getOperator());
                    $value = $this->normalizeValue($filter->getOperator(), $filter->getValue());

                    if ($column->getDataJunction() === Column::DATA_DISJUNCTION) {
                        $this->query->addOr($this->query->expr()->field($column->getField())->$operator($value));
                    } else {
                        $this->query->field($column->getField())->$operator($value);
                    }
                }
            }

            $validColumns[] = $column;
        }

        if ($page > 0) {
            $this->query->skip($page * $limit);
        }

        if ($limit > 0) {
            if ($maxResults !== null && ($maxResults - $page * $limit < $limit)) {
                $limit = $maxResults - $page * $limit;
            }

            $this->query->limit($limit);
        } elseif ($maxResults !== null) {
            $this->query->limit($maxResults);
        }

        //call overridden prepareQuery or associated closure
        $this->prepareQuery($this->query);

        //execute and get results
        $result = new Rows();

        // I really don't know if Cursor is the right type returned (I mean, every single type).
        // As I didn't find out this information, I'm gonna test it with Cursor returned only.
        $cursor = $this->query->getQuery()->execute();

        $this->count = $cursor->count();

        foreach ($cursor as $resource) {
            $row = new Row();
            $properties = $this->getClassProperties($resource);

            foreach ($validColumns as $column) {
                if (isset($properties[strtolower($column->getId())])) {
                    $row->setField($column->getId(), $properties[strtolower($column->getId())]);
                }
            }

            $this->addReferencedFields($row, $resource);

            //call overridden prepareRow or associated closure
            if (($modifiedRow = $this->prepareRow($row)) !== null) {
                $result->addRow($modifiedRow);
            }
        }

        return $result;
    }
public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gridDataJunction = Column::DATA_CONJUNCTION)
    {
        $this->query = $this->getQueryBuilder();

        $validColumns = [];
        foreach ($columns as $column) {

            //checks if exists '.' notation on referenced columns and build query if it's filtered
            $subColumn = explode('.', $column->getId());
            if (count($subColumn) > 1 && isset($this->referencedMappings[$subColumn[0]])) {
                $this->addReferencedColumnn($subColumn, $column);

                continue;
            }

            $this->query->select($column->getField());

            if ($column->isSorted()) {
                $this->query->sort($column->getField(), $column->getOrder());
            }

            if ($column->isPrimary()) {
                $column->setFilterable(false);
            } elseif ($column->isFiltered()) {
                // Some attributes of the column can be changed in this function
                $filters = $column->getFilters('document');

                foreach ($filters as $filter) {
                    //normalize values
                    $operator = $this->normalizeOperator($filter->getOperator());
                    $value = $this->normalizeValue($filter->getOperator(), $filter->getValue());

                    if ($column->getDataJunction() === Column::DATA_DISJUNCTION) {
                        $this->query->addOr($this->query->expr()->field($column->getField())->$operator($value));
                    } else {
                        $this->query->field($column->getField())->$operator($value);
                    }
                }
            }

            $validColumns[] = $column;
        }

        if ($page > 0) {
            $this->query->skip($page * $limit);
        }

        if ($limit > 0) {
            if ($maxResults !== null && ($maxResults - $page * $limit < $limit)) {
                $limit = $maxResults - $page * $limit;
            }

            $this->query->limit($limit);
        } elseif ($maxResults !== null) {
            $this->query->limit($maxResults);
        }

        //call overridden prepareQuery or associated closure
        $this->prepareQuery($this->query);

        //execute and get results
        $result = new Rows();

        // I really don't know if Cursor is the right type returned (I mean, every single type).
        // As I didn't find out this information, I'm gonna test it with Cursor returned only.
        $cursor = $this->query->getQuery()->execute();

        $this->count = $cursor->count();

        foreach ($cursor as $resource) {
            $row = new Row();
            $properties = $this->getClassProperties($resource);

            foreach ($validColumns as $column) {
                if (isset($properties[strtolower($column->getId())])) {
                    $row->setField($column->getId(), $properties[strtolower($column->getId())]);
                }
            }

            $this->addReferencedFields($row, $resource);

            //call overridden prepareRow or associated closure
            if (($modifiedRow = $this->prepareRow($row)) !== null) {
                $result->addRow($modifiedRow);
            }
        }

        return $result;
    }
@param ColumnsIterator $columns
@param int                                      $page             Page Number
@param int                                      $limit            Rows Per Page
@param int                                      $gridDataJunction Grid data junction

@return \APY\DataGridBundle\Grid\Rows