diff --git a/examples/view.json b/examples/view.json new file mode 100644 index 0000000..13bd46e --- /dev/null +++ b/examples/view.json @@ -0,0 +1,27 @@ +{ + "meta": { + "rows": { + "username": "Логин", + "email": "Email", + "created_at": "Создан", + "updated_at": "Обновлен" + }, + "perPage": 10, + "currentPage": 1, + "baseUrl": "\/admin\/user", + "actions": [], + "params": { + "class": "table table-bordered", + "border": "2" + } + }, + "data": { + "id": 1, + "username": "rrr", + "email": "rrr@mail.ru", + "password_hash": "sdgh46eyrtghsdret", + "role": 1, + "created_at": "15.07.2024", + "updated_at": null + } +} \ No newline at end of file diff --git a/examples/view.php b/examples/view.php new file mode 100644 index 0000000..916f1b4 --- /dev/null +++ b/examples/view.php @@ -0,0 +1,11 @@ +create(); +$table->render(); \ No newline at end of file diff --git a/src/ViewJsonTable.php b/src/ViewJsonTable.php index 46d1647..96a6ac6 100644 --- a/src/ViewJsonTable.php +++ b/src/ViewJsonTable.php @@ -23,7 +23,7 @@ class ViewJsonTable { $this->json = $json; $this->data = json_decode($this->json, true); - $this->dataJson = json_decode($this->data['data']['data'], true); + $this->dataJson = $this->data['data']; } @@ -31,20 +31,25 @@ class ViewJsonTable public function beginTable(): void { $paramsStr = $this->createParams($this->data['meta']['params']); - $hook = $this->beforePrintTable; - $this->html = $hook(); + + //Хук перед выводом ячейки + if (isset($this->beforePrintTable)){ + $hook = $this->beforePrintTable; + $this->html = $hook(); + } + $this->html .= "
" . $column . ": | " . $this->dataJson[$key] . " |
---|---|
" . $row . ": | " . $this->dataJson[$key] . " |