Make sortable.

@param string $db_field

@return $this
164621
public function makeSortable($db_field = null)
    {
        // reverse sorting
        $reverse = false;
        if ($db_field[0] == '-') {
            $reverse = true;
            $db_field = substr($db_field, 1);
        }

        // used db field
        if (!$db_field) {
            $db_field = $this->last_column;
        }

        switch ((string) $this->sortby) {

            // we are already sorting by this column
            case $db_field:
                $info = array('1', $reverse ? 0 : ('-'.$db_field));
                $this->sortby_db = $db_field;
                break;

            // We are sorted reverse by this column
            case '-'.$db_field:
                $info = array('2', $reverse ? $db_field : '0');
                $this->sortby_db = '-'.$db_field;
                break;

            // we are not sorted by this column
            default:
                $info = array('0', $reverse ? ('-'.$db_field) : $db_field);
        }

        $this->columns[$db_field]['sortable'] = $info;

        return $this;
    }
1305031
public function order($field, $desc = false)
    {
        if(count($this->models) > 0) {
            $instance = $this->reflection->newInstance();
            $string = $instance->isString($field);
            usort($this->models, function ($a, $b) use ($field, $string) {
                if($string) {
                    return strcmp($a[$field], $b[$field]);
                }
                return $a[$field] - $b[$field];
            });
            if ($desc) {
                $this->models = array_reverse($this->models);
            }
        }
        return $this;
    }
1112072
public function fkAddOrderBy($field, $fkField, $order = 'ASC')
    {
        $alias = $this->tableAlias();
        $this->queryBuilder->join($this->getFullFieldName($field), $alias);
        $this->queryBuilder->addOrderBy($this->getFullFieldName($fkField, $alias), $order);

        return $this;
    }
696847
def orderBy(self, field, direct="desc"):
        
        if direct == "desc":
            self._query = self._query.order_by(r.desc(field))
        else:
            self._query = self._query.order_by(r.asc(field))

        return self
1214027
public function byFieldValue(
        string $field,
        string $order
    ): SortBy {
        $this->sortsBy[] = [
            'type' => self::TYPE_FIELD,
            'field' => Item::getPathByField($field),
            'order' => $order,
        ];

        return $this;
    }
765418
public function order($field, $order = '')
    {
        if (is_array($field)) {
            $this->options['sort'] = $field;
        } else {
            $this->options['sort'][$field] = 'asc' == strtolower($order) ? 1 : -1;
        }
        return $this;
    }
57101
public function orderBy($fields, $defaultDirection = 'ASC')
    {
        if (!is_array($fields)) {
            $fields = array($fields);
        }

        foreach ($fields as $key => $value) {
            $field = $key;
            $type = $value;
            if (is_int($key)) {
                $field = $value;
                $type = $defaultDirection;
            }
            if (!$field instanceof Raw) {
                $field = $this->addTablePrefix($field);
            }
            $this->statements['orderBys'][] = compact('field', 'type');
        }

        return $this;
    }
603898
public function orderBy(string $field, $order = 'asc')
    {
        $order = strtolower($order) == 'asc' ? 'asc' : 'desc';
        $this->ordination[$field] = $order;

        return $this;
    }
809038
public function sort($sort, $data) {
		if (count($this->files) == 0) {
			return $this;
		}
		// defines fields list if it's need
		for ($i = 0; $i < count($sort); $i++) {
			$fieldname = $sort[$i]['name'];
			if (!isset($this->files[0][$fieldname])) {
				if (isset($data[$fieldname])) {
					$fieldname = $data[$fieldname]['db_name'];
					$sort[$i]['name'] = $fieldname;
				} else {
					$fieldname = false;
				}
			}
		}

		// for every sorting field will sort
		for ($i = 0; $i < count($sort); $i++) {
			// if field, setted in sort parameter doesn't exist, continue
			if ($sort[$i]['name'] == false) {
				continue;
			}
			// sorting by current field
			$flag = true;
			while ($flag == true) {
				$flag = false;
				// checks if previous sorting fields are equal
				for ($j = 0; $j < count($this->files) - 1; $j++) {
					$equal = true;
					for ($k = 0; $k < $i; $k++) {
						if ($this->files[$j][$sort[$k]['name']] != $this->files[$j + 1][$sort[$k]['name']]) {
							$equal = false;
						}
					}
					// compares two records in list under current sorting field and sorting direction
					if (((($this->files[$j][$sort[$i]['name']] > $this->files[$j + 1][$sort[$i]['name']])&&($sort[$i]['direction'] == 'ASC'))||(($this->files[$j][$sort[$i]['name']] < $this->files[$j + 1][$sort[$i]['name']])&&($sort[$i]['direction'] == 'DESC')))&&($equal == true)) {
						$c = $this->files[$j];
						$this->files[$j] = $this->files[$j+1];
						$this->files[$j+1] = $c;
						$flag = true;
					}
				}
			}
		}
		return $this;
	}
832411
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)) {
			$this->data_source->getSqlBuilder()->setOrder([], []);

			foreach ($sort as $column => $order) {
				$this->data_source->order("$column $order");
			}
		} else {
			/**
			 * Has the statement already a order by clause?
			 */
			if (!$this->data_source->getSqlBuilder()->getOrder()) {
				$this->data_source->order($this->primary_key);
			}
		}

		return $this;
	}
134036
public function recalculateSort()
    {
        $owner = $this->owner;
        $db = $this->owner->getDb();
        $builder = new QueryBuilder($db);

        $orderFields = [$this->sortAttribute => 'asc'];
        foreach ($owner->primaryKey() as $field) {
            if ($field != $this->sortAttribute) {
                $orderFields[$field] = 'asc';
            }
        }
        // recalculate sort
        $query = $builder->update(
            $owner->tableName(),
            [$this->sortAttribute => new Expression('(@sortingCount:=(@sortingCount+1))')],
            $this->getCondition(),
            $params
        ) . ' ' . $builder->buildOrderBy($orderFields);
        $db->createCommand('set @sortingCount=-1;' . $query, $params)->execute();
        // update in current record
        if (!$owner->getIsNewRecord()) {
            $owner->{$this->sortAttribute} = $owner->findOne($owner->getPrimaryKey())->{$this->sortAttribute};
        }
    }
1219958
public function orderBy($column, $sort = 'ASC')
    {
        $sort = strtoupper($sort);
        if ($sort !== 'DESC') {
            $sort = 'ASC';
        }
        $this->order_by[$column] = $sort;

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

        return $this;
    }
76186
public function sortByCallable(callable $sortFunc)
    {
        $this->prepare();

        if (!is_array($this->_map)) {
            return $this;
        }

        usort($this->_map, $sortFunc);

        return $this;
    }
301491
public function setSortable($sortable, $sortable_flags = null)
    {
        $this->sortable = (bool) $sortable;
        $this->sortable_flags = $sortable_flags;

        return $this;
    }
1198471
public static function bootSortableTrait()
    {
        static::creating(
            function ($model) {
                /* @var Model $model */
                $sortableField = static::getSortableField();
                $query = static::applySortableGroup(static::on($model->getConnectionName()), $model);

                // only automatically calculate next position with max+1 when a position has not been set already
                if ($model->$sortableField === null) {
                    $model->setAttribute($sortableField, $query->max($sortableField) + 1);
                }
            }
        );
    }
1204077
public function sortBy(string $field, callable $callback = null) : Vector
    {
        $values = $this->_sortBy($field, $callback);
        $this->setValues($values);
        return $this;
    }