public function setSortableColumns($columns = array())
    {
        $repository = $this->get('orm.em')->getRepository($this->getEntityClass());

        foreach ($columns as $column => $options) {
            $sortMethodName = 'getQueryBuilderOrderedBy'.ucfirst(strtolower($column));
            if (method_exists($repository, $sortMethodName)) {
                $columns[$column]['sortable'] = true;
                continue;
            }
            if (property_exists($this->getEntityClass(), $column)) {
                // OneToMany and ManyToMany relations are not sortable
                $reader = new \Doctrine\Common\Annotations\AnnotationReader();
                $reflProperty = new \ReflectionProperty($this->getEntityClass(), $column);
                $OneToMany = $reader->getPropertyAnnotation($reflProperty, '\Doctrine\ORM\Mapping\OneToMany');
                $ManyToMany = $reader->getPropertyAnnotation($reflProperty, '\Doctrine\ORM\Mapping\ManyToMany');
                if (!$OneToMany && !$ManyToMany) {
                    $columns[$column]['sortable'] = true;
                    continue;
                }
            }
            $columns[$column]['sortable'] = false;
        }

        return $columns;
    }
public function setSortableColumns($columns = array())
    {
        $repository = $this->get('orm.em')->getRepository($this->getEntityClass());

        foreach ($columns as $column => $options) {
            $sortMethodName = 'getQueryBuilderOrderedBy'.ucfirst(strtolower($column));
            if (method_exists($repository, $sortMethodName)) {
                $columns[$column]['sortable'] = true;
                continue;
            }
            if (property_exists($this->getEntityClass(), $column)) {
                // OneToMany and ManyToMany relations are not sortable
                $reader = new \Doctrine\Common\Annotations\AnnotationReader();
                $reflProperty = new \ReflectionProperty($this->getEntityClass(), $column);
                $OneToMany = $reader->getPropertyAnnotation($reflProperty, '\Doctrine\ORM\Mapping\OneToMany');
                $ManyToMany = $reader->getPropertyAnnotation($reflProperty, '\Doctrine\ORM\Mapping\ManyToMany');
                if (!$OneToMany && !$ManyToMany) {
                    $columns[$column]['sortable'] = true;
                    continue;
                }
            }
            $columns[$column]['sortable'] = false;
        }

        return $columns;
    }
public function setSortableColumns ( $ columns = array ( ) ) { $ repository = $ this -> get ( 'orm.em' ) -> getRepository ( $ this -> getEntityClass ( ) ) ; foreach ( $ columns as $ column => $ options ) { $ sortMethodName = 'getQueryBuilderOrderedBy' . ucfirst ( strtolower ( $ column ) ) ; if ( method_exists ( $ repository , $ sortMethodName ) ) { $ columns [ $ column ] [ 'sortable' ] = true ; continue ; } if ( property_exists ( $ this -> getEntityClass ( ) , $ column ) ) { // OneToMany and ManyToMany relations are not sortable $ reader = new \ Doctrine \ Common \ Annotations \ AnnotationReader ( ) ; $ reflProperty = new \ ReflectionProperty ( $ this -> getEntityClass ( ) , $ column ) ; $ OneToMany = $ reader -> getPropertyAnnotation ( $ reflProperty , '\Doctrine\ORM\Mapping\OneToMany' ) ; $ ManyToMany = $ reader -> getPropertyAnnotation ( $ reflProperty , '\Doctrine\ORM\Mapping\ManyToMany' ) ; if ( ! $ OneToMany && ! $ ManyToMany ) { $ columns [ $ column ] [ 'sortable' ] = true ; continue ; } } $ columns [ $ column ] [ 'sortable' ] = false ; } return $ columns ; }
Defines a sortable parameter on each column if it's sortable

@param array $columns List columns configuration

@return array
Defines a sortable parameter on each column if it s sortable