Set the default sorted column (required).

@param string $direction (default: "asc", accepts "asc" or "desc")

@return \Okipa\LaravelBootstrapTableList\TableListColumn
@throws ErrorException
421615
public function sortByDefault(string $direction = 'asc'): TableListColumn
    {
        // we check if the method has already been called
        if ($this->getAttribute('tableList')->sortBy || $this->getAttribute('tableList')->sortDir) {
            $errorMessage = 'The « sortByDefault() » method has already been called. '
                            . 'You only can sort a column by default once.';
            throw new ErrorException($errorMessage);
        }
        // we set the sort attribute
        $this->getAttribute('tableList')->sortBy = $this->getAttribute('attribute');
        // we set the sort direction
        $acceptedDirections = ['asc', 'desc'];
        $errorMessage = 'Invalid « $direction » argument for « sortByAttribute() » method. Has to be « asc » or '
                        . '« desc ». « ' . $direction . ' » given.';
        if (! in_array($direction, $acceptedDirections)) {
            throw new InvalidArgumentException($errorMessage);
        }
        $this->getAttribute('tableList')->setAttribute('sortDir', $direction);

        return $this;
    }
634963
public function sortByRelation($column, $direction = 'ASC')
    {
        $relations = explode('.', $column);
        $column    = array_pop($relations);

        /** @var \Illuminate\Database\Eloquent\Model $model */
        $model = $this->repository->makeModel();

        $this->instance->getQuery()->orders = [];

        foreach ($relations as $relation) {
            /* @var Relation $relationClass */
            $this->joinRelation($relationClass = $model->{camel_case($relation)}());

            $model = $relationClass->getRelated();
        }

        $selectedColumns = $this->instance->getQuery()->columns;

        $addColumn = DB::raw("{$this->repository->makeModel()->getTable()}.*");

        if (is_array($selectedColumns) && array_search('*', $selectedColumns, true) !== null) {
            $this->instance->getQuery()->columns[array_search('*', $selectedColumns, true)] = $addColumn;
        } else {
            $this->instance->select($addColumn);
        }

        $this->instance->orderBy("{$model->getTable()}.{$column}", $direction);

        return $this;
    }
1355298
public function setDefaultColumnAlignment($alignment)
    {
        Assert::oneOf($alignment, Alignment::all(), 'The default column alignment must be one of the Alignment constants. Got: %s');

        $this->defaultColumnAlignment = $alignment;

        return $this;
    }
727294
public function orderBy(string $componentId, string $direction)
    {
        $this->rowCriteria->orderBy($componentId, $direction);

        return $this;
    }
512277
public function orderBy($column, $direction = IQueryBuilder::ORDER_ASC)
    {
        if ($direction == IQueryBuilder::ORDER_ASC || $direction == IQueryBuilder::ORDER_DESC) {
            $this->orderConditions[$column] = $direction;
        }

        return $this;
    }
493180
public function sortBy($field, $direction = 'asc', $flags = null)
    {
        $this->sortByField = $field;

        // Normalize direction.
        $direction = strtolower($direction);

        if ($direction === 'asc' || $direction === 'desc') {
            $this->sortByDirection = $direction;
        }

        if (is_null($flags)) {
            $this->sortByFlags = SORT_NATURAL + SORT_FLAG_CASE;
        }

        return $this;
    }
1103909
protected function sortData($directions)
	{
		if(empty($directions) || empty($this->rawData))
			return;
		$args=array();
		$dummy=array();
		foreach($directions as $name=>$descending)
		{
			$column=array();
			$fields_array=preg_split('/\.+/',$name,-1,PREG_SPLIT_NO_EMPTY);
			foreach($this->rawData as $index=>$data)
				$column[$index]=$this->getSortingFieldValue($data, $fields_array);
			$args[]=&$column;
			$dummy[]=&$column;
			unset($column);
			$direction=$descending ? SORT_DESC : SORT_ASC;
			$args[]=&$direction;
			$dummy[]=&$direction;
			unset($direction);
		}

		// This fix is used for cases when main sorting specified by columns has equal values
		// Without it it will lead to Fatal Error: Nesting level too deep - recursive dependency?
		$args[]=range(1,count($this->rawData));
		$args[]=SORT_ASC;
		$args[]=SORT_NUMERIC;

		$args[]=&$this->rawData;
		call_user_func_array('array_multisort', $args);
	}
1155401
public function sortby($column, $direction= 'ASC') {
        /* The direction can only be ASC or DESC; anything else is bogus */
        if (!in_array(strtoupper($direction), array('ASC', 'DESC', 'ASCENDING', 'DESCENDING'), true)) {
            $direction = '';
        }

        if (!static::isValidClause($column)) {
            $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'SQL injection attempt detected in sortby column; clause rejected');
        } elseif (!empty($column)) {
            $this->query['sortby'][] = array('column' => $column, 'direction' => $direction);
        }
        return $this;
    }
1108976
public function changeOrdering($direction)
    {
        $allowedDirections = array('asc', 'desc');
        $direction = strtolower($direction);
        $isInArray = in_array($direction, $allowedDirections, true);
        if (!empty($direction) && $isInArray) {
            if ($direction == 'asc') {
                $direction = 'desc';
            } else {
                $direction = 'asc';
            }
        }
        return $direction;
    }
667404
function orderBy($column, $dir = null) {
		if (null !== $dir && '' !== $dir) {
			$dir = strtoupper($dir);
			if ($dir !== self::ASC && $dir !== self::DESC) {
				throw new RuntimeException("$dir is not a valid sorting direction.");
			}
			$column .= ' ' . $dir;
		}
		$this->orders[] = trim($column);
		return $this;
	}
265540
public function setOrderDirection($direction)
    {

        $direction = strtolower($direction);

        if (!in_array($direction, ['asc', 'desc'])) {
            throw new \InvalidArgumentException('$direction must be "asc" or "desc"');
        }

        $this->orderDirection = $direction;
        return $this;
    }
185289
public function setCurrent($direction)
    {
        list($option, $key) = $this->getCurrent();

        $option->setCurrent(false);

        $new_key = $this->getCurrentKey($direction, $option, $key);

        $this->checkboxes[$new_key]->setCurrent();
    }
973724
final public function setListOrderBy($fields, $direction = "ASC")
    {

        $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' ' . $direction : ' ASC';
        $orderby = NULL;
        //Clean up the order by field list
        if (!empty($fields) && !is_array($fields)) {
            $temp = array();
            foreach (explode(',', $fields) as $part) {
                $part = trim($part);
                $temp[] = $part;
            }

            $orderby = implode(', ', $temp);
        } else if (is_array($fields)) {
            $temp = array();
            foreach ($fields as $field) {
                $part = trim($field);
                $temp[] = $part;
            }
            $orderby = implode(', ', $temp);
        }


        if (!empty($orderby)) {
            $this->listOrderByStatement = "\nORDER BY " . $orderby . $direction;
        }
        //Return this object
        return $this;
    }
439733
protected function setOrderByDirection($direction)
    {
        $direction = strtolower($direction);

        if ($direction == 'desc' || $direction == 'asc') {
            $this->orderByDirection = $direction;
        }
    }
513245
public function setDefaultSort(array $sort)
    {
        static $replace = ['asc' => Column::ORDER_ASC, 'desc' => Column::ORDER_DESC];

        foreach ($sort as $column => $dir) {
            $dir = strtr(strtolower($dir), $replace);
            if (!in_array($dir, $replace)) {
                throw new Exception("Dir '$dir' for column '$column' is not allowed.");
            }

            $this->defaultSort[$column] = $dir;
        }

        return $this;
    }
716832
public function scopeSort(Builder $query, $column, $direction)
    {
        if (!in_array($column, $this->sortable)) {
            return $query;
        }

        return $query->orderBy($column, $direction);
    }
707440
public function orderBy($column, $direction = Table::ORDER_ASC) {
        $this->orderBy[] = '`' . Util::camelTo_($column) . '` ' . $direction;
        return $this;
    }