diff --git a/src/DataTable.php b/src/DataTable.php index 0f65ce80..38aaba92 100644 --- a/src/DataTable.php +++ b/src/DataTable.php @@ -228,7 +228,7 @@ public function getPaginationData(): PaginationData return $this->paginationData; } - public function getFiltrationData(): FiltrationData + public function getFiltrationData(): ?FiltrationData { return $this->filtrationData; } @@ -308,7 +308,7 @@ public function isExporting(): bool public function hasActiveFilters(): bool { - return $this->filtrationData->hasActiveFilters(); + return (bool) $this->filtrationData?->hasActiveFilters(); } public function handleRequest(mixed $request): void diff --git a/src/DataTableInterface.php b/src/DataTableInterface.php index 7b812672..e3b1d0b8 100644 --- a/src/DataTableInterface.php +++ b/src/DataTableInterface.php @@ -35,7 +35,7 @@ public function getSortingData(): SortingData; public function getPaginationData(): PaginationData; - public function getFiltrationData(): FiltrationData; + public function getFiltrationData(): ?FiltrationData; public function getPersonalizationData(): PersonalizationData; diff --git a/src/Type/DataTableType.php b/src/Type/DataTableType.php index c0bb6b1b..80cb2252 100644 --- a/src/Type/DataTableType.php +++ b/src/Type/DataTableType.php @@ -229,6 +229,10 @@ private function createFilterViews(DataTableView $view, DataTableInterface $data { $filters = []; + if (!$dataTable->getConfig()->isFiltrationEnabled()) { + return []; + } + foreach ($dataTable->getConfig()->getFilters() as $filter) { $data = $dataTable->getFiltrationData()->getFilterData($filter->getName()) ?? new FilterData();