Sort columns in the order specified, columns that exists
in the dataset but not in the sorted_columns will be
appended to the end.

@param string[] $sorted_columns
769306
public function sort(array $sorted_columns): self
    {
        $diff = array_diff_assoc($sorted_columns, array_unique($sorted_columns));
        if (count($diff) > 0) {
            $cols = implode(',', $diff);
            throw new Exception\DuplicateColumnException(__METHOD__ . " Duplicate column found in paramter sorted_columns : '$cols'");
        }
        $columns = [];

        foreach ($sorted_columns as $idx => $column) {
            if (!$this->exists($column)) {
                throw new Exception\InvalidArgumentException(__METHOD__ . " Column '$column' does not exists.");
            }
            $columns[$column] = $this->get($column);
        }
        // Appending eventual non sorted columns at the end
        $columns = array_merge($columns, (array) $this->columns);
        $this->columns->exchangeArray($columns);

        return $this;
    }
813764
public function sortMultipleColumn($columns)
    {
        $compareFuncList = [];
        foreach($columns as $colName=>$asc) {
            $columnFormat = array_key_exists($colName, $this->dataFormats) ? $this->dataFormats[$colName] : Format::STRING;
            $compareFuncList[$colName] = $this->_getFunctionForFormat($columnFormat, $asc);
        }

        $this->uSortMultipleColumn($compareFuncList);
        return $this;
    }
839936
def sort_index(self):
        
        sort = sorted_list_indexes(self._index)
        # sort index
        self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
        # each column
        for c in range(len(self._data)):
            self._data[c] = blist([self._data[c][i] for i in sort]) if self._blist else [self._data[c][i] for i in sort]
511752
protected function sortArray(&$array, $sort_flags = SORT_REGULAR)
    {
        if (! is_array($array)) {
            return;
        }

        ksort($array, $sort_flags);

        foreach ($array as &$arr) {
            $this->sortArray($arr, $sort_flags);
        }
    }
874880
public void setSortedColumn(String sortedColumn) throws CmsIllegalArgumentException {

        // check if the parameter is valid
        if ((getMetadata().getColumnDefinition(sortedColumn) == null)
            || !getMetadata().getColumnDefinition(sortedColumn).isSorteable()) {
            return;
        }
        // reset view
        setCurrentPage(1);
        // only reverse order if the column to sort is already sorted
        if (sortedColumn.equals(m_sortedColumn)) {
            if (m_currentSortOrder == CmsListOrderEnum.ORDER_ASCENDING) {
                m_currentSortOrder = CmsListOrderEnum.ORDER_DESCENDING;
            } else {
                m_currentSortOrder = CmsListOrderEnum.ORDER_ASCENDING;
            }
            if (!m_metadata.isSelfManaged()) {
                if (m_filteredItems == null) {
                    m_filteredItems = new ArrayList<CmsListItem>(getAllContent());
                }
                Collections.reverse(m_filteredItems);
            }
            return;
        }
        // sort new column
        m_sortedColumn = sortedColumn;
        m_currentSortOrder = CmsListOrderEnum.ORDER_ASCENDING;
        if (!m_metadata.isSelfManaged()) {
            if (m_filteredItems == null) {
                m_filteredItems = new ArrayList<CmsListItem>(getAllContent());
            }
            I_CmsListItemComparator c = getMetadata().getColumnDefinition(sortedColumn).getListItemComparator();
            Collections.sort(m_filteredItems, c.getComparator(sortedColumn, getWp().getLocale()));
        }
    }
1083100
public function makeAdminColumnsSortable($columns)
    {
        $admin_columns = $this->getAdminColumns();
        if (!Arr::iterable($admin_columns)) {
            return $columns;
        }

        foreach ($admin_columns as $k) {
            $columns[$k] = $k;
        }
        return $columns;
    }
186420
public function get_sort_columns() {
        if (!$this->setup) {
            throw new coding_exception('Cannot call get_sort_columns until you have called setup.');
        }

        if (empty($this->prefs['sortby'])) {
            return array();
        }

        foreach ($this->prefs['sortby'] as $column => $notused) {
            if (isset($this->columns[$column])) {
                continue; // This column is OK.
            }
            if (in_array($column, get_all_user_name_fields()) &&
                    isset($this->columns['fullname'])) {
                continue; // This column is OK.
            }
            // This column is not OK.
            unset($this->prefs['sortby'][$column]);
        }

        return $this->prefs['sortby'];
    }
940516
private function appendSortBy($sortBy, $sortMethod, $search)
    {
        foreach ($sortBy as $column) {
            $search->addSort(new FieldSort($column, $sortMethod));
        }
    }
1061854
def sortByColumn(self, index, direction):
        
        if self.isPaged() and not self.isFullyLoaded():
            self.reorder(index, direction)
        else:
            super(XOrbTreeWidget, self).sortByColumn(index, direction)
1091172
private function sortAdaptors()
    {
        $this->sorted = array();

        if (isset($this->adaptors)) {
            krsort($this->adaptors);
            $this->sorted = call_user_func_array('array_merge', $this->adaptors);
        }
    }
110704
private function sortArrayMultiple(array $data, $sortConditions)
    {
        $sortArguments = [];
        foreach ($sortConditions as $sortCondition) {
            $sortParameters = $this->getSortArrayParameter($sortCondition);

            // fetch column data
            $column = $sortParameters[0];

            $dataCol = [];
            foreach ($data as $key => $row) {
                if (!isset($row[$column])) {
                    $value = '';
                } else {
                    $value = $row[$column];
                }
                $dataCol[$key] = $value;
            }

            $sortArguments[] = [
                $dataCol,
                $sortParameters[1],
                $sortParameters[2],
            ];
        }

        return $this->applyMultiSort($data, $sortArguments);
    }
1135389
public function sort(Sorting $sorting)
	{
		if (is_callable($sorting->getSortCallback())) {
			call_user_func(
				$sorting->getSortCallback(),
				$this->data_source,
				$sorting->getSort()
			);

			return $this;
		}

		$sort = $sorting->getSort();

		if (!empty($sort)) {
			foreach ($sort as $column => $order) {
				$this->data_source->addOrderBy($this->checkAliases($column), $order);
			}
		} else {
			/**
			 * Has the statement already a order by clause?
			 */
			if (!$this->data_source->getDQLPart('orderBy')) {
				$this->data_source->orderBy($this->checkAliases($this->primary_key));
			}
		}

		return $this;
	}
397141
private void sortByMetaData(List<MetaDataCol> sortColumns)
  {
    if (sortColumns == null || sortColumns.isEmpty())
    {
      sort(new Object[]
      {
        PROP_DOC_NAME
      }, new boolean[]
      {
        true
      });

      return;
    }

    Object[] sortByColumns = new Object[sortColumns.size()];
    boolean[] ascendingOrDescending = new boolean[sortColumns.size()];

    for (int i = 0; i < sortColumns.size(); i++)
    {

      sortByColumns[i] = sortColumns.get(i).getColName();

      ascendingOrDescending[i] = sortColumns.get(i).ascending;

    }

    sort(sortByColumns, ascendingOrDescending);

  }
75986
public function sortBlocks( array $sortArray )
    {
        $sortedBlocks = array();

        foreach( $sortArray as $sortItem )
        {
            $blocksToBeRemoved = array();
            
            foreach( $this->attributes['blocks'] as $block )
            {
                if ( $block->attribute('id') === $sortItem )
                    $sortedBlocks[] = $block;
                
                if ( $block->toBeRemoved() )
                    $blocksToBeRemoved[] = $block;
            }
        }

        $sortedBlocks = array_merge( $sortedBlocks, $blocksToBeRemoved );

        $this->attributes['blocks'] = $sortedBlocks;
    }
1080041
public function sort(DataStructure\Sort $sorting)
    {
        $sortings = [];

        foreach ($sorting as $sortingEntity) {

            if ($this->isExcludedProperty($sortingEntity->getProperty())) {
                continue;
            }

            $sortings[$sortingEntity->getProperty()] =
                $sortingEntity instanceof DataStructure\Sort\Asc ? 'asc' : 'desc';
        }

        $this->criteria->orderBy($sortings);
    }
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;
    }
924317
public static function sortCol($result,$array)
    {
        foreach ($result as $key => $fields) {
         $dados[] = self::sortkeys($fields,$array);
        }

        if(!$dados){ $dados = [];}

        return $dados;
    }