diff --git a/examples/simple.php b/examples/simple.php index 09ec7a3..1785c7e 100644 --- a/examples/simple.php +++ b/examples/simple.php @@ -2,6 +2,8 @@ require_once "../vendor/autoload.php"; +use Itguild\Tables\Filter\InputFilter; +use Itguild\Tables\Filter\SelectFilter; use Itguild\Tables\ListJsonTable; $json = file_get_contents('simple.json'); @@ -10,32 +12,49 @@ $table = new ListJsonTable($json); $table->columns([ "created_at" => [ "format" => "date:Y-m-d", - 'filter' => ["input" => "date"] + 'filter' => [ + 'class' => InputFilter::class, + 'param' => 'date' + ] ], 'description' => [ "format" => "html", "style" => ["width" => "300px"], - "filter" => ["input" => ["radio" => ["hello", "bye"]]], + "filter" => [ + 'class' => InputFilter::class, + 'param' => 'text' + ], "value" => function ($cell) { return "$cell"; } ], 'description2' => [ - "filter" => ["input" => "text"], + "format" => "html", + "filter" => [ + 'class' => SelectFilter::class, + 'param' => ['black', 'red', 'green', 'blue', 'yellow'] + ], ], 'status' => [ "format" => "integer", - "filter" => ["select" => getStatusLabel()], + "filter" => [ + 'class' => SelectFilter::class, + 'param' => getStatusLabel() + ], "value" => function ($cell) { return getStatusLabel()[$cell]; }], + 'k33' => [ + "format" => "integer", + 'filter' => [ + 'class' => InputFilter::class, + 'param' => 'range' + ] + ], 'email' => function ($cell) { return "$cell"; }, ]); -//$table->setBeforePrintCell(function ($key, $data) { -// return $key == "email" ? "$data" : $data; -//}); $table->afterPrint(function ($meta) { return "
"; -//// print_r($value); -// $this->html .= ""; -// } -// return $this->html . "
";
-// print_r(current($this->beforePrintCell[$column]['filter']));
- return current($this->beforePrintCell[$column]['filter']);
-// }
- }
- }
- }
- return "text";
- }
+// protected function getTagFromCustomColumn(string $column): string
+// {
+// if (is_array($this->beforePrintCell[$column])) {
+// if (isset($this->beforePrintCell[$column]['filter'])) {
+// if (is_array($this->beforePrintCell[$column]['filter'])) {
+//// foreach ($this->beforePrintCell[$column]['filter'] as $key => $value) {
+// return key($this->beforePrintCell[$column]['filter']);
+//// }
+// }
+// }
+// }
+// return "text";
+// }
+//
+// protected function getFilterFromCustomColumn(string $column)
+// {
+// if (is_array($this->beforePrintCell[$column])) {
+// if (isset($this->beforePrintCell[$column]['filter'])) {
+// if (is_array($this->beforePrintCell[$column]['filter'])) {
+//// foreach ($this->beforePrintCell[$column]['filter'] as $value) {
+//// echo "";
+//// print_r(current($this->beforePrintCell[$column]['filter']));
+// return current($this->beforePrintCell[$column]['filter']);
+//// }
+// }
+// }
+// }
+// return "text";
+// }
}
\ No newline at end of file
diff --git a/src/ListJsonTable.php b/src/ListJsonTable.php
index 2209028..98058e0 100644
--- a/src/ListJsonTable.php
+++ b/src/ListJsonTable.php
@@ -147,13 +147,21 @@ class ListJsonTable extends JasonTable
$this->actionsArray = array_merge($this->actionsArray, $this->customActionsArray);
}
- private function getCurrentFilter(string $filter): false|string
+ private function getCurrentFilter(string $column)
{
- return match ($filter) {
- 'input' => InputFilter::class,
- 'select' => SelectFilter::class,
- default => false,
- };
+// return match ($filter) {
+// 'input' => InputFilter::class,
+// 'select' => SelectFilter::class,
+// default => false,
+// };
+ if (is_array($this->beforePrintCell[$column])) {
+ if (isset($this->beforePrintCell[$column]['filter'])) {
+ if (is_array($this->beforePrintCell[$column]['filter'])) {
+ return $this->beforePrintCell[$column]['filter'];
+ }
+ }
+ }
+ return false;
}
public function getCustomColumns($id = null): void
@@ -269,12 +277,18 @@ class ListJsonTable extends JasonTable
foreach ($columnKeys as $key){
if ($this->issetFilter($key)){
// $this->html .= " ";
- $item = $this->getCurrentFilter($this->getTagFromCustomColumn($key));
- $objItem = new $item([
- 'data' => $this->getFilterFromCustomColumn($key),
+// $item = $this->getCurrentFilter($this->getTagFromCustomColumn($key));
+// $objItem = new $item([
+// 'data' => $this->getFilterFromCustomColumn($key),
+// 'name' => $key
+// ]);
+// $this->html .= $objItem->fetch();
+ $arr = $this->getCurrentFilter($key);
+ $class = new $arr['class']([
+ 'param' => $arr['param'],
'name' => $key
]);
- $this->html .= $objItem->fetch();
+ $this->html .= $class->fetch();
}
else {
$this->html .= " ";