From f20f408f1243c282e0dc42a891132e604f94f22f Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Wed, 28 Aug 2024 15:09:34 +0300 Subject: [PATCH] add value to filter --- examples/simple.php | 9 ++++++--- src/Filter/Filter.php | 2 ++ src/Filter/InputFilter.php | 2 +- src/Filter/SelectFilter.php | 8 ++++++-- src/ListJsonTable.php | 3 ++- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/examples/simple.php b/examples/simple.php index 1785c7e..40de293 100644 --- a/examples/simple.php +++ b/examples/simple.php @@ -22,7 +22,8 @@ $table->columns([ "style" => ["width" => "300px"], "filter" => [ 'class' => InputFilter::class, - 'param' => 'text' + 'param' => 'text', + 'value' => 'value' ], "value" => function ($cell) { return "$cell"; @@ -32,14 +33,16 @@ $table->columns([ "format" => "html", "filter" => [ 'class' => SelectFilter::class, - 'param' => ['black', 'red', 'green', 'blue', 'yellow'] + 'param' => ['black', 'red', 'green', 'blue', 'yellow'], + 'value' => 'red' ], ], 'status' => [ "format" => "integer", "filter" => [ 'class' => SelectFilter::class, - 'param' => getStatusLabel() + 'param' => getStatusLabel(), + 'value' => 'Активный' ], "value" => function ($cell) { return getStatusLabel()[$cell]; diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 5ee3a5b..500f9f5 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -7,10 +7,12 @@ abstract class Filter public string $html = ''; public string|array $param; public string $name; + public string $value; public function __construct(array $source) { $this->param = $source['param'] ?? ''; $this->name = $source['name']; + $this->value = $source['value'] ?? ''; } abstract public function fetch(); diff --git a/src/Filter/InputFilter.php b/src/Filter/InputFilter.php index 24e9acb..85ed406 100644 --- a/src/Filter/InputFilter.php +++ b/src/Filter/InputFilter.php @@ -9,6 +9,6 @@ class InputFilter extends Filter public function fetch() { - return ""; + return ""; } } \ No newline at end of file diff --git a/src/Filter/SelectFilter.php b/src/Filter/SelectFilter.php index 15931fb..3150040 100644 --- a/src/Filter/SelectFilter.php +++ b/src/Filter/SelectFilter.php @@ -11,9 +11,13 @@ class SelectFilter extends Filter { $this->html = ""; + $this->html .= "value='$this->value'"; return $this->html; } } \ No newline at end of file diff --git a/src/ListJsonTable.php b/src/ListJsonTable.php index accede0..46a008e 100644 --- a/src/ListJsonTable.php +++ b/src/ListJsonTable.php @@ -286,7 +286,8 @@ class ListJsonTable extends JasonTable $filter = $this->getCurrentFilter($key); $class = new $filter['class']([ 'param' => $filter['param'], - 'name' => $key + 'name' => $key, + 'value' => $filter['value'] ]); $this->html .= $class->fetch(); }