Create the column sorter.

@return string
339823
public function sorter()
    {
        if (!$this->sortable) {
            return '';
        }

        $icon = 'fa-sort';
        $type = 'desc';

        if ($this->isSorted()) {
            $type = $this->sort['type'] == 'desc' ? 'asc' : 'desc';
            $icon .= "-amount-{$this->sort['type']}";
        }

        // set sort value
        $sort = ['column' => $this->name, 'type' => $type];
        if (isset($this->cast)) {
            $sort['cast'] = $this->cast;
        }

        $query = app('request')->all();
        $query = array_merge($query, [$this->grid->model()->getSortName() => $sort]);

        $url = url()->current().'?'.http_build_query($query);

        return "<a class=\"fa fa-fw $icon\" href=\"$url\"></a>";
    }
239835
protected function applySortForm(): SortConfig
    {
        $form = $this->getForm();
        $sortableForm = $form->get(self::SORTABLE_FORM_NAME);
        /** @var FormInterface $sortConfigForm */
        $sortConfigForm = $sortableForm->get(self::SORT_CONFIG_FORM_NAME);
        /** @var SortConfig $sortConfig */
        $sortConfig = $sortConfigForm->getData();

        foreach ($this->getConfiguration()->getSortable() as $sortable) {
            /** @var SubmitButton $button */
            $button = $sortableForm->get($sortable);
            if ($button->isClicked()) {
                if ($sortConfig->getColumn() === $sortable) {
                    $sortConfig->switchDirection();
                } else {
                    $sortConfig->setColumn($sortable);
                    $sortConfig->setDirection(false);
                }
            }
        }

        return $sortConfig;
    }
1223120
public function columnCount()
    {
        $maxCol = 0;

        foreach ($this->_layout as $row => $items) {
            foreach ($items as $column => $item) {
                $maxCol = max($column, $maxCol);
            }
        }

        return $maxCol;
    }
384150
public function columns()
    {
        $this->hook->filter(
            'manage_users_columns',
            [$this->user->getColumns(), 'setNames']
        )->dispatch();

        $this->hook->action(
            'manage_users_custom_column',
            function ($value, $name, $id) {
                ob_start();

                $column = $this->user->getColumn($name);

                if (isset($column)) {
                    $column->render($id);
                }

                return ob_get_clean();
            },
            ['numberOfArguments' => 3]
        )->dispatch();
    }
1099318
protected function get_column_info()
    {
        if (isset($this->column_headers)) {
            return $this->column_headers;
        }

        $columns   = get_column_headers($this->screen);
        $hidden    = get_hidden_columns($this->screen);
        $_sortable = apply_filters("manage_{$this->screen->id}_sortable_columns", $this->get_sortable_columns());
        $sortable  = array();

        foreach ($_sortable as $id => $data) {
            if (empty($data)) {
                continue;
            }

            $data = (array) $data;

            if (!isset($data[1])) {
                $data[1] = false;
            }

            $sortable[$id] = $data;
        }

        $this->column_headers = array($columns, $hidden, $sortable);

        return $this->column_headers;
    }
458304
public function onSort()
    {
        if ($column = post('sortColumn')) {

            /*
             * Toggle the sort direction and set the sorting column
             */
            $sortOptions = ['column' => $this->getSortColumn(), 'direction' => $this->sortDirection];

            if ($column != $sortOptions['column'] || $sortOptions['direction'] == 'asc') {
                $this->sortDirection = $sortOptions['direction'] = 'desc';
            }
            else {
                $this->sortDirection = $sortOptions['direction'] = 'asc';
            }

            $this->sortColumn = $sortOptions['column'] = $column;

            $this->putSession('sort', $sortOptions);

            /*
             * Persist the page number
             */
            $this->currentPageNumber = post('page');

            return $this->onRefresh();
        }
    }
84287
public function getListSorting()
    {
        $aListSorting = parent::getListSorting();

        if (array_keys($aListSorting['oxcountry']) === ['oxactive']) {
            $aListSorting['oxcountry'][$this->_getSecondSortFieldName()] = 'asc';
        }

        return $aListSorting;
    }
312697
public function getQualifiedOrderByColumns()
    {
        $columns   = $this->cmsOrderBy;
        $qualified = [];

        if (empty($columns)) return [];

        foreach ($columns as $column => $direction) {
            $qualified[ $this->getTable() . '.' . $column ] = $direction;
        }

        return $qualified;
    }
852493
public function isSortable(): TableListColumn
    {
        $this->getAttribute('tableList')->getAttribute('sortableColumns')->add($this);
        $this->setAttribute('isSortableColumn', true);

        return $this;
    }
404445
protected function _getSortCol()
    {
        $aVisibleNames = $this->_getVisibleColNames();
        $iCol = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('sort');
        $iCol = $iCol ? (( int ) str_replace('_', '', $iCol)) : 0;
        $iCol = (!isset($aVisibleNames[$iCol])) ? 0 : $iCol;

        return $iCol;
    }
1111687
protected function buildOrder()
    {
        $result = '';

        $orders = (array) $this->getOrder();
        foreach ($orders as $field => $direction) {
            if ($result != '') {
                $result.=',';
            }
            $result.=$field.' '.($direction === SORT_DESC ? 'DESC' : 'ASC');
        }
        if ($result != '') {
            $result = 'ORDER BY '.$result;
        }

        return $result;
    }
1172021
private function getTableHf()
    {
        if ($this->HFContent) return $this->HFContent;

        ob_start();
        ?>
        <tr>
            <?php // Start constructing the table header columns ?>
            <?php foreach ($this->columns as $column_key => $column_options) : ?>

                <?php $sortable_class = $this->getSortableClass($column_key); ?>

                <th data-column-name="<?php echo $column_key; ?>"
                    class="<?php echo $sortable_class; ?> <?php echo $this->getColumnOption($column_key, self::COLUMN_OPTION_CLASSES); ?>"
                    <?php echo $this->getColumnOption($column_key, self::COLUMN_OPTION_THEAD_ATTR) ?>>

                    <?php echo $this->getColumnHeaderStructure($column_key, $column_options); ?>
                </th>
            <?php endforeach; ?>
        </tr>

        <?php

        $this->HFContent = ob_get_clean();

        return $this->HFContent;
    }
413117
public function getSortField()
    {
        if ($this->_sortField === false) {
            return [];
        }

        if ($this->_sortField) {
            // 
            if (is_array($this->_sortField)) {
                return [$this->name => $this->_sortField];
            } 

            return [$this->name => [
                'asc' => [$this->_sortField => SORT_ASC],
                'desc' => [$this->_sortField => SORT_DESC]
            ]];
        }
        
        return [$this->name];
    }
362852
protected function buildOrderBy()
    {
        if (!$this->order_by) {
            return '';
        }

        if ($this->order_asc) {
            return ' ORDER BY' . $this->indentCsv($this->order_by) . ' ASC';
        } else {
            return ' ORDER BY' . $this->indentCsv($this->order_by) . ' DESC';
        }
    }
999526
private function getSortOrder()
    {
        return [
            $this->translator->trans(/** @Desc("Ascending") */ 'content_type.sort_field.ascending', [], 'content_type') => Location::SORT_ORDER_ASC,
            $this->translator->trans(/** @Desc("Descending") */ 'content_type.sort_field.descending', [], 'content_type') => Location::SORT_ORDER_DESC,
        ];
    }
518022
public function &buildColumnList()
    {

        $str = "";
        $ct = 0;

        // Build Select Column List
        foreach ($this->columns as $k => $col) {
            if ($col->in_select) {
                if ($ct > 0) {
                    $str .= ",";
                }

                $str .= " ";

                if ($col->table_name) {
                    $str .= $col->table_name . ".";
                }

                $str .= $col->column_name;

                if (($col->query_name)) {
                    $str .= " " . $col->query_name;
                }

                $ct++;
            }
        }
        //die;
        return $str;
    }
82785
public function getSelect() {
        if ($this->fields && $this->fields != '*' && (!(is_string($this->fields) && '*' == $this->fields[0] && 'END) AS `__parentRelationKey`' == substr($this->fields, -29)))) {
            if (is_string($this->fields)) {
                return $this->fields;
            }
            $columns = array();
            foreach ($this->fields as $field) { // @TODO: column generation here.
                $columns[] = trim($field);
            }
            return implode(', ', $columns);
        }
        if ((is_string($this->fields) && '*' == $this->fields[0] && 'END) AS `__parentRelationKey`' == substr($this->fields, -29))){
            return implode(', ', $this->getAllColumnsForSelect()) . substr($this->fields, 1);
        } else {
            return implode(', ', $this->getAllColumnsForSelect());
        }
    }