From 77a306a0f67c398ec2e941ff2cc6643a3d3cb2f6 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Thu, 22 Aug 2024 13:08:25 +0300 Subject: [PATCH] add custom columns filter --- examples/simple.php | 5 +++-- src/JasonTable.php | 10 ++++++++++ src/ListJsonTable.php | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/simple.php b/examples/simple.php index 768bb10..0584bd7 100644 --- a/examples/simple.php +++ b/examples/simple.php @@ -9,12 +9,13 @@ $table = new ListJsonTable($json); $table->columns([ "created_at" => [ - "format" => "date:Y-m-d" + "format" => "date:Y-m-d", + 'filter' => "date" ], 'description' => [ "format" => "html", "style" => ["width" => "300px"], - "filter" => '', + "filter" => "text", "value" => function ($cell) { return "$cell"; } diff --git a/src/JasonTable.php b/src/JasonTable.php index 5080b1d..53be197 100644 --- a/src/JasonTable.php +++ b/src/JasonTable.php @@ -90,4 +90,14 @@ class JasonTable return $styleStr; } + + protected function getFilterFromCustomColumn(string $column) + { + if (is_array($this->beforePrintCell[$column])) { + if (isset($this->beforePrintCell[$column]['filter'])) { + return $this->beforePrintCell[$column]['filter']; + } + } + return "text"; + } } \ No newline at end of file diff --git a/src/ListJsonTable.php b/src/ListJsonTable.php index 051de24..20be360 100644 --- a/src/ListJsonTable.php +++ b/src/ListJsonTable.php @@ -251,7 +251,7 @@ class ListJsonTable extends JasonTable $this->html .= "
"; foreach ($columnKeys as $key){ if ($this->issetFilter($key)){ - $this->html .= ""; + $this->html .= ""; } else { $this->html .= "";