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:
Andrew
2021-08-11 14:37:37 +03:00
committed by GitHub
parent c94d7049c5
commit 463a67bc73
3 changed files with 38 additions and 3 deletions

View File

@ -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];
}