protected function applyQuerySort(QueryBuilder $queryBuilder, $alias = 'a')
    {
        $sort = $this->get('request')->get('sort');
        $order = $this->get('request')->get('order');

        if ($sort) {
            $repository = $this->get('orm.em')->getRepository($this->getEntityClass());
            // sort using the getQueryBuilderOrderedBy* magic method if defined
            $sortMethodName = 'getQueryBuilderOrderedBy'.ucfirst(strtolower($sort));
            if (method_exists($repository, $sortMethodName)) {
                $queryBuilder = call_user_method_array($sortMethodName, $repository, array($order, $queryBuilder));
            }
            // else sort by property name if exists
            elseif ($sort && property_exists($this->getEntityClass(), $sort)) {
                $queryBuilder->orderBy($alias.'.'.$sort, $order);
            }
        }
        // if empty sort use Gedmo Sortable annotation if enable
        elseif ($sort = $this->getSortableColumn()) {
            // pre order by group if defined
            if ($sortGroup = $this->getSortableGroup()) {
                $queryBuilder->orderBy($alias.'.'.$sortGroup);
            }
            $queryBuilder->addOrderBy($alias.'.'.$sort);
        }

        return $queryBuilder;
    }