From b381929a5fcbceb9dcb7878d6b50fbe2ec746c74 Mon Sep 17 00:00:00 2001 From: David Palomares Date: Fri, 26 Nov 2021 11:49:29 +0100 Subject: [PATCH] CanFilterRecords: check if we have a default filter when no filter is selected, and apply that filter --- .../tables/src/Concerns/CanFilterRecords.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/tables/src/Concerns/CanFilterRecords.php b/packages/tables/src/Concerns/CanFilterRecords.php index 5ab41c298c..c2c2efa1b3 100644 --- a/packages/tables/src/Concerns/CanFilterRecords.php +++ b/packages/tables/src/Concerns/CanFilterRecords.php @@ -26,11 +26,19 @@ trait CanFilterRecords protected function applyFilters($query) { - if ( - ! $this->isFilterable() || - $this->filter === '' || - $this->filter === null + if (! $this->isFilterable()) { + return $query; + } + + // Check if we have a default filter when no filter is selected + if (($this->filter === '' || $this->filter === null) && + ($defaultFilter = $this->getTable()->getDefaultFilter()) ) { + $this->filter = $defaultFilter->getName(); + } + + // We don't have any filter selected and no default one + if ($this->filter === '' || $this->filter === null) { return $query; }