diff --git a/examples/simple.php b/examples/simple.php index 88e15d7..3efe225 100644 --- a/examples/simple.php +++ b/examples/simple.php @@ -9,14 +9,18 @@ $table = new ListJsonTable($json); //$table->column("status", function ($ceil){ // return getStatusLabel()[$ceil]; //}); -//$table->columns([ -// 'status' => function ($ceil) { -// return getStatusLabel()[$ceil]; -// }, -// 'email' => function ($ceil) { -// return "$ceil"; -// } -//]); + +$table->columns([ + 'status' => function ($ceil) { + return getStatusLabel()[$ceil]; + }, + 'email' => function ($ceil) { + return "$ceil"; + }, + 'description' => function ($ceil) { + return "$ceil"; + } +]); //$table->setBeforePrintCell(function ($key, $data) { // return $key == "email" ? "$data" : $data; //}); diff --git a/src/ListJsonTable.php b/src/ListJsonTable.php index b054122..90512ff 100644 --- a/src/ListJsonTable.php +++ b/src/ListJsonTable.php @@ -18,7 +18,8 @@ class ListJsonTable private string $json; private int $count = 0; - private \Closure|false $beforePrintCell; +// private \Closure|false $beforePrintCell; + private array $beforePrintCell; private \Closure|false $beforePrintHook; private \Closure|false $afterPrintHook; private string $baseUrl; @@ -34,7 +35,8 @@ class ListJsonTable #[NoReturn] public function __construct(string $json) { - $this->beforePrintCell = false; +// $this->beforePrintCell = false; + $this->beforePrintCell = []; $this->json = $json; $this->data = json_decode($this->json, true); $this->baseUrl = $this->data['meta']['baseUrl'] ?? ''; @@ -131,9 +133,15 @@ class ListJsonTable } foreach ($row as $key => $ceil) { if ($this->issetColumn($key) and $this->is_fillable($key)) { - if ($this->beforePrintCell) { - $hook = $this->beforePrintCell; - $ceil = $hook($key, $ceil); + foreach ($this->beforePrintCell as $column => $closure) { +// if ($this->beforePrintCell) { +// $hook = $this->beforePrintCell; +// $ceil = $hook($key, $ceil); +// } + if ($key == $column) { + $hook = $closure; + $ceil = $hook($ceil); + } } $this->html .= "