Returns the current sorting column, saved in a session or cached.
2244
protected function getSortColumn()
    {
        if (!$this->isSortable()) {
            return false;
        }

        if ($this->sortColumn !== null) {
            return $this->sortColumn;
        }

        /*
         * User preference
         */
        if ($this->showSorting && ($sortOptions = $this->getSession('sort'))) {
            $this->sortColumn = $sortOptions['column'];
            $this->sortDirection = $sortOptions['direction'];
        }

        /*
         * Supplied default
         */
        else {
            if (is_string($this->defaultSort)) {
                $this->sortColumn = $this->defaultSort;
                $this->sortDirection = 'desc';
            }
            elseif (is_array($this->defaultSort) && isset($this->defaultSort['column'])) {
                $this->sortColumn = $this->defaultSort['column'];
                $this->sortDirection = $this->defaultSort['direction'] ?? 'desc';
            }
        }

        /*
         * First available column
         */
        if ($this->sortColumn === null || !$this->isSortable($this->sortColumn)) {
            $columns = $this->visibleColumns ?: $this->getVisibleColumns();
            $columns = array_filter($columns, function ($column) { return $column->sortable; });
            $this->sortColumn = key($columns);
            $this->sortDirection = 'desc';
        }

        return $this->sortColumn;
    }
233063
def resort(self, columnName):
        
        csc = self.currentSortColumn
        newSortColumn = self.columns[columnName]
        if newSortColumn is None:
            raise Unsortable('column %r has no sort attribute' % (columnName,))
        if csc is newSortColumn:
            self.isAscending = not self.isAscending
        else:
            self.currentSortColumn = newSortColumn
            self.isAscending = True
        return self.isAscending
313388
def sort_ascending(self, key):
        """"""

        row, col, tab = key

        scells = self.grid.code_array[:, col, tab]

        def sorter(i):
            sorted_ele = scells[i]
            return sorted_ele is None, sorted_ele

        sorted_row_idxs = sorted(xrange(len(scells)), key=sorter)

        self.replace_cells(key, sorted_row_idxs)

        self.grid.ForceRefresh()
86083
public Table sortDescendingOn(String... columnNames) {
        Sort key = getSort(columnNames);
        return sortOn(key);
    }
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();
        }
    }
194169
protected function getSortableColumn()
    {
        $reader = new AnnotationReader();
        $reflClass = new ReflectionClass($this->getEntityClass());
        foreach ($reflClass->getProperties() as $property) {
            $reflProperty = new ReflectionProperty($this->getEntityClass(), $property->name);
            $annotation = $reader->getPropertyAnnotation($reflProperty, '\Gedmo\Mapping\Annotation\SortablePosition');
            if ($annotation) {
                return $property->name;
            }
        }
    }
714191
def sortByColumn(self, column, order=QtCore.Qt.AscendingOrder):
        
        super(XTreeWidget, self).sortByColumn(column, order)
        self._sortOrder = order
392864
function sortRows(rows, columns, dirs) {
    if (!rows)
        return [];
    if (!dirs || !dirs.length || !columns)
        return rows.slice();
    /**
     * record the row ordering of results from prior sort operations (if applicable)
     * this is necessary to guarantee stable sorting behavior
     */
    var rowToIndexMap = new Map();
    rows.forEach(function (row, index) { return rowToIndexMap.set(row, index); });
    var temp = rows.slice();
    var cols = columns.reduce(function (obj, col) {
        if (col.comparator && typeof col.comparator === 'function') {
            obj[col.prop] = col.comparator;
        }
        return obj;
    }, {});
    // cache valueGetter and compareFn so that they
    // do not need to be looked-up in the sort function body
    var cachedDirs = dirs.map(function (dir) {
        var prop = dir.prop;
        return {
            prop: prop,
            dir: dir.dir,
            valueGetter: column_prop_getters_1.getterForProp(prop),
            compareFn: cols[prop] || orderByComparator
        };
    });
    return temp.sort(function (rowA, rowB) {
        for (var _i = 0, cachedDirs_1 = cachedDirs; _i < cachedDirs_1.length; _i++) {
            var cachedDir = cachedDirs_1[_i];
            // Get property and valuegetters for column to be sorted
            var prop = cachedDir.prop, valueGetter = cachedDir.valueGetter;
            // Get A and B cell values from rows based on properties of the columns
            var propA = valueGetter(rowA, prop);
            var propB = valueGetter(rowB, prop);
            // Compare function gets five parameters:
            // Two cell values to be compared as propA and propB
            // Two rows corresponding to the cells as rowA and rowB
            // Direction of the sort for this column as SortDirection
            // Compare can be a standard JS comparison function (a,b) => -1|0|1
            // as additional parameters are silently ignored. The whole row and sort
            // direction enable more complex sort logic.
            var comparison = cachedDir.dir !== types_1.SortDirection.desc ?
                cachedDir.compareFn(propA, propB, rowA, rowB, cachedDir.dir) :
                -cachedDir.compareFn(propA, propB, rowA, rowB, cachedDir.dir);
            // Don't return 0 yet in case of needing to sort by next property
            if (comparison !== 0)
                return comparison;
        }
        if (!(rowToIndexMap.has(rowA) && rowToIndexMap.has(rowB)))
            return 0;
        /**
         * all else being equal, preserve original order of the rows (stable sort)
         */
        return rowToIndexMap.get(rowA) < rowToIndexMap.get(rowB) ? -1 : 1;
    });
}
1218093
def sort_collection_by_column(collection, column, order)
      sorter = column.sort[:method]
      collection = collection.sort_by do |record|
        value = sorter.is_a?(Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter.to_s)
        value = '' if value.nil?
        value
      end
      collection.reverse! if order.casecmp('DESC').zero?
      collection
    end
1139154
protected function sortColumns()
    {
        $this->config->getColumns()->sort(function (FieldConfig $a, FieldConfig $b) {
            return $a->getOrder() > $b->getOrder();
        });
    }
82986
protected function _sort()
    {
        if (!isset($this->_sorts) || count($this->_sorts) === 0) {
            return;
        }

        $columns      = $this->_dataGrid->getActiveColumnsOrdered();
        $sorts        = $this->_sorts;
        $sortPosition = $this->_sortPositions;

        usort($this->_output, function ($a, $b) use ($columns, $sortPosition, $sorts) {
            foreach ($sortPosition as $colIndex) {
                $sort = $sorts[$colIndex];
                /** @var $sort\RBM\Datagrid\Data\Sort */
                /** @var $column\RBM\Datagrid\Column */
                $column = $columns[$colIndex];
                $valueA = $column->getSortData($a);
                $valueB = $column->getSortData($b);

                if ($valueA == $valueB) {
                    continue;
                }

                $arr = array($valueA, $valueB);

                $args = array_merge(array(&$arr), array($sort->getDirection(), $sort->getType()));
                call_user_func_array('array_multisort', $args);

                return ($arr[0] == $valueA) ? -1 : 1;
            }
            return 0;
        });
    }
1065128
@SuppressWarnings("rawtypes")
    protected SortKey getSortKey(JTable table, int column) {
        RowSorter rowSorter = table.getRowSorter();
        if (rowSorter == null) {
            return null;
        }

        List sortedColumns = rowSorter.getSortKeys();
        if (!sortedColumns.isEmpty()) {
            return (SortKey) sortedColumns.get(0);
        }
        return null;
    }
308399
protected function getActualSortDirection($column = null)
    {
        $column = $column ?: $this->activeSort;

        if (null !== $this->activeSortDescending) {
            return $this->activeSortDescending ? 'desc' : 'asc';
        }

        if ( ! isset($this->getModelInformation()->list->columns[$column])) {

            if (null === $column) {
                return $this->getActualSortDirection($this->getDefaultSort());
            }

            return 'asc';
        }

        $direction = $this->getModelInformation()->list->columns[$column]->sort_direction;

        return strtolower($direction) === 'desc' ? 'desc' : 'asc';
    }
615230
protected function getCurrentListOrder($update_session = true)
    {
        return $this->getListOrderFromSession(
            $this->objectName,
            $this->orderRequestParameterName,
            $this->defaultListOrder
        );
    }
358794
protected function getSortableClass($column_key)
    {
        $classes = NULL;

        if ($this->getColumnOption($column_key, self::COLUMN_OPTION_SORTABLE))
        {
            $classes .= 'sorting ';
            if (array_key_exists($column_key, $this->columnOrders))
            {
                $order_method = $this->columnOrders[$column_key];
                switch ($order_method)
                {
                    case 'desc':
                        $classes .= 'sorting_asc ';
                        break;
                    default:
                        $classes .= 'sorting_desc ';
                }
            }
        }

        return $classes;
    }
484786
private static SortOrder getSortOrder(JTable table, int column)
    {
        List<? extends SortKey> sortKeys = table.getRowSorter().getSortKeys();
        for (int i=0; i<sortKeys.size(); i++)
        {
            SortKey sortKey = sortKeys.get(i);
            if (sortKey.getColumn() == table.convertColumnIndexToModel(column))
            {
                return sortKey.getSortOrder();                        
            }
        }
        return null;
    }
753920
public function getSortedCellList()
    {
        $sortKeys = array();
        foreach ($this->getCellList() as $coord) {
            sscanf($coord, '%[A-Z]%d', $column, $row);
            $sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
        }
        ksort($sortKeys);

        return array_values($sortKeys);
    }