Allow sorting of lists by invisible columns

A previous bug fix applied here (18af35d928) forced only visible columns to be sortable to prevent an error from occurring if someone sorts by a column that is then removed from the columns list.

This change results in the same fix, but simply checks that the column is sortable (which would be false if the column no longer exists). This would  allow columns that are invisible but are also sortable to still be used for sorting purposes.

Fixes #796, #709
Refs:
- https://github.com/octobercms/october/issues/5227
This commit is contained in:
Ben Thomson 2022-12-12 15:07:41 +08:00
parent d0d066f6c2
commit c563f20f87

View File

@ -541,7 +541,7 @@ class Lists extends WidgetBase
/*
* Apply sorting
*/
if (($sortColumn = $this->getSortColumn()) && !$this->showTree && in_array($sortColumn, array_keys($this->getVisibleColumns()))) {
if (($sortColumn = $this->getSortColumn()) && !$this->showTree) {
if (($column = array_get($this->allColumns, $sortColumn)) && $column->valueFrom) {
$sortColumn = $this->isColumnPivot($column)
? 'pivot_' . $column->valueFrom
@ -1596,7 +1596,7 @@ class Lists extends WidgetBase
return false;
}
if ($this->sortColumn !== null) {
if ($this->sortColumn !== null && $this->isSortable($this->sortColumn)) {
return $this->sortColumn;
}