mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 21:41:19 +08:00
Add ability to turn the sorting off for a clicked column in GridView with multisort (#18826)
* Add ability to turn the sorting off for a clicked column in GridView with multisort * Update Sort.php * Fix SortTest * Update CHANGELOG.md Co-authored-by: Bizley <pawel@positive.codes>
This commit is contained in:
@ -438,14 +438,25 @@ class Sort extends BaseObject
|
||||
$definition = $this->attributes[$attribute];
|
||||
$directions = $this->getAttributeOrders();
|
||||
if (isset($directions[$attribute])) {
|
||||
$direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
|
||||
if ($this->enableMultiSort) {
|
||||
if ($directions[$attribute] === SORT_ASC) {
|
||||
$direction = SORT_DESC;
|
||||
} else {
|
||||
$direction = null;
|
||||
}
|
||||
} else {
|
||||
$direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
|
||||
}
|
||||
|
||||
unset($directions[$attribute]);
|
||||
} else {
|
||||
$direction = isset($definition['default']) ? $definition['default'] : SORT_ASC;
|
||||
}
|
||||
|
||||
if ($this->enableMultiSort) {
|
||||
$directions = array_merge([$attribute => $direction], $directions);
|
||||
if ($direction !== null) {
|
||||
$directions = array_merge([$attribute => $direction], $directions);
|
||||
}
|
||||
} else {
|
||||
$directions = [$attribute => $direction];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user