Skip to content

Commit

Permalink
Prevent multisort if it is disabled (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Jul 29, 2024
1 parent f32bd33 commit 0ad195d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/BaseListView.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ abstract class BaseListView extends Widget
protected UrlParameterProviderInterface|null $urlParameterProvider = null;

private bool $ignoreMissingPage = true;
protected bool $enableMultiSort = false;

/**
* @psalm-var PageNotFoundExceptionCallback|null
Expand Down Expand Up @@ -174,6 +175,13 @@ final public function urlParameterProvider(?UrlParameterProviderInterface $provi
return $new;
}

final public function enableMultiSort(bool $value = true): self
{
$new = clone $this;
$new->enableMultiSort = $value;
return $new;
}

/**
* Renders the data models.
*
Expand Down Expand Up @@ -371,6 +379,9 @@ private function prepareDataReaderByParams(
$sortObject = $dataReader->getSort();
if ($sortObject !== null) {
$order = OrderHelper::stringToArray($sort);
if (!$this->enableMultiSort) {
$order = array_slice($order, 0, 1, true);
}
$this->prepareOrder($order);
$dataReader = $dataReader->withSort($sortObject->withOrder($order));
}
Expand Down
8 changes: 0 additions & 8 deletions src/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ final class GridView extends BaseListView
private array $headerCellAttributes = [];
private array $bodyCellAttributes = [];

private bool $enableMultiSort = false;
private bool $keepPageOnSort = false;
private ?string $sortableHeaderClass = null;
private string|Stringable $sortableHeaderPrepend = '';
Expand Down Expand Up @@ -136,13 +135,6 @@ public function filterErrorsContainerAttributes(array $attributes): self
return $new;
}

public function enableMultiSort(bool $value = true): self
{
$new = clone $this;
$new->enableMultiSort = $value;
return $new;
}

public function keepPageOnSort(bool $value = true): self
{
$new = clone $this;
Expand Down

0 comments on commit 0ad195d

Please sign in to comment.