From 4a12eeccfd284695c012837242155f25cbb4e774 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Wed, 7 Aug 2024 11:56:33 +0300 Subject: [PATCH 1/3] some fix --- src/ListJsonTable.php | 8 ++++---- src/ViewJsonTable.php | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ListJsonTable.php b/src/ListJsonTable.php index 62b1d89..26c7742 100644 --- a/src/ListJsonTable.php +++ b/src/ListJsonTable.php @@ -276,10 +276,10 @@ class ListJsonTable extends JasonTable if ($this->pagination) { $options = [ 'countItem' => $this->data['meta']['total'], - 'perPage' => $this->data['meta']['perPage'], - 'currentPage' => $this->data['meta']['currentPage'], - 'baseUrl' => $this->baseUrl, - 'prefix' => $this->data['meta']['paginationPrefix'], + 'perPage' => $this->data['meta']['perPage'] ?? 10, + 'currentPage' => $this->data['meta']['currentPage'] ?? 1, + 'baseUrl' => $this->baseUrl ?? '', + 'prefix' => $this->data['meta']['paginationPrefix'] ?? '/page', ]; $pagination = new Pagination($options); $pagination->create(); diff --git a/src/ViewJsonTable.php b/src/ViewJsonTable.php index 96cd7b7..181d699 100644 --- a/src/ViewJsonTable.php +++ b/src/ViewJsonTable.php @@ -13,9 +13,14 @@ class ViewJsonTable extends JasonTable private array $dataJson; public function __construct($json) { + $this->beforePrintCell = false; $this->json = $json; $this->data = json_decode($this->json, true); $this->dataJson = $this->data['data']; + $this->beforePrintHook = function () { + }; + $this->afterPrintHook = function () { + }; } public function beginTable(): void From 1bd82eb40b28a4b8b4c3b1fbeeabb523326a8632 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Wed, 7 Aug 2024 12:16:42 +0300 Subject: [PATCH 2/3] some fix --- src/JasonTable.php | 2 +- src/ListJsonTable.php | 4 ++-- src/ViewJsonTable.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/JasonTable.php b/src/JasonTable.php index 276891b..bef4652 100644 --- a/src/JasonTable.php +++ b/src/JasonTable.php @@ -20,7 +20,7 @@ class JasonTable $this->beforePrintCell = $closure; } - public function getCustomCell(string $key, string $cell) + public function getCustomCell(string $key, string|null $cell) { if (is_array($this->beforePrintCell)) { foreach ($this->beforePrintCell as $currentKey => $closure) { diff --git a/src/ListJsonTable.php b/src/ListJsonTable.php index 26c7742..9f374b2 100644 --- a/src/ListJsonTable.php +++ b/src/ListJsonTable.php @@ -29,7 +29,7 @@ class ListJsonTable extends JasonTable #[NoReturn] public function __construct(string $json) { - $this->beforePrintCell = false; + $this->beforePrintCell = []; $this->json = $json; $this->data = json_decode($this->json, true); $this->baseUrl = $this->data['meta']['baseUrl'] ?? ''; @@ -86,7 +86,7 @@ class ListJsonTable extends JasonTable } foreach ($row as $key => $cell) { if ($this->issetColumn($key) and $this->is_fillable($key)) { - if($this->beforePrintCell and $cell !== null) { + if($this->beforePrintCell) { $cell = $this->getCustomCell($key, $cell); } $this->html .= "" . $cell . ""; diff --git a/src/ViewJsonTable.php b/src/ViewJsonTable.php index 181d699..ab051c0 100644 --- a/src/ViewJsonTable.php +++ b/src/ViewJsonTable.php @@ -39,7 +39,7 @@ class ViewJsonTable extends JasonTable { foreach ($this->data['meta']['rows'] as $key => $row){ if ($this->issetRow($key)){ - if ($this->beforePrintCell and $this->dataJson[$key] !== null) { + if ($this->beforePrintCell) { $this->dataJson[$key] = $this->getCustomCell($key, $this->dataJson[$key]); } $this->html .= "" . $row . "" . $this->dataJson[$key] . ""; From d98ddded07131f602486783f5f016002ea7d7fb7 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Wed, 7 Aug 2024 12:43:14 +0300 Subject: [PATCH 3/3] fix view json table --- src/ViewJsonTable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ViewJsonTable.php b/src/ViewJsonTable.php index ab051c0..4c8cebc 100644 --- a/src/ViewJsonTable.php +++ b/src/ViewJsonTable.php @@ -13,7 +13,7 @@ class ViewJsonTable extends JasonTable private array $dataJson; public function __construct($json) { - $this->beforePrintCell = false; + $this->beforePrintCell = []; $this->json = $json; $this->data = json_decode($this->json, true); $this->dataJson = $this->data['data'];