public function addOrderBy(QueryBuilder $queryBuilder, Request $request, TableModel $table)
    {
        $sorting = $table->getSorting();
        $rootAlias = $this->getRootAlias($queryBuilder);

        $orderByField = $request->query->get('order_by', null);
        $orderDirection = $request->query->get('order_dir', null);

        if (null !== $orderByField && true === in_array($orderByField, $sorting->getSortableFields())) {
            $sorting->setIndex($orderByField);
        }

        if (null !== $orderDirection && true === in_array(strtolower($orderDirection), $this->getOrderDirections())) {
            $sorting->setDirection($orderDirection);
        }

        $queryBuilder
            ->orderBy(sprintf("%s.%s", $rootAlias, $sorting->getIndex()), $sorting->getDirection());

        return $queryBuilder;
    }