From 453917ea1abd8264821104588c79559f1ba5f6d0 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Thu, 29 Aug 2024 13:08:43 +0300 Subject: [PATCH] table filter fix --- examples/simple.json | 2 +- src/ListJsonTable.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/examples/simple.json b/examples/simple.json index 7b13196..a4fc309 100644 --- a/examples/simple.json +++ b/examples/simple.json @@ -15,11 +15,11 @@ "currentPage": "1", "showActionColumn": true, "showFiltersRow": true, - "filter": true, "total": 10, "paginationPrefix": "/page", "params": {"class": "table table-bordered", "border": "1"} }, + "filters": ["email", "status"], "data": [ {"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "created_at": "17.06.2024", "status": "1"}, {"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "created_at": "18.06.2024", "status": "1"}, diff --git a/src/ListJsonTable.php b/src/ListJsonTable.php index 405c696..f573b53 100644 --- a/src/ListJsonTable.php +++ b/src/ListJsonTable.php @@ -6,6 +6,7 @@ use Exception; use Itguild\Tables\ActionColumn\DeleteActionColumn; use Itguild\Tables\ActionColumn\EditActionColumn; use Itguild\Tables\ActionColumn\ViewActionColumn; +use Itguild\Tables\Filter\InputTextFilter; use Itguild\Tables\traits\CreateParams; use JetBrains\PhpStorm\NoReturn; @@ -270,12 +271,19 @@ class ListJsonTable extends JasonTable foreach ($columnKeys as $key){ if ($this->issetFilter($key)){ $filter = $this->getCurrentFilter($key); - $class = new $filter['class']([ + $params = [ 'param' => $filter['param'] ?? '', 'name' => $key, 'value' => $filter['value'] ?? '', - ]); - $this->html .= $class->fetch(); + ]; + if ($filter){ + $class = new $filter['class']($params); + $this->html .= $class->fetch(); + } + else { + $class = new InputTextFilter($params); + $this->html .= $class->fetch(); + } } else { $this->html .= "";