4 Commits

Author SHA1 Message Date
a2284e3bf2 columns update 2024-08-08 13:26:45 +03:00
9e7c83b680 fix View Json Table 2024-08-07 14:31:07 +03:00
b374744261 Merge branch 'master' of https://git.itguild.info/ItGuild/tables 2024-08-07 14:21:00 +03:00
c6918c85b3 fix View Jason Table 2024-08-07 14:10:26 +03:00
4 changed files with 32 additions and 17 deletions

View File

@ -5,7 +5,7 @@
"id": "ID", "id": "ID",
"email": "Email", "email": "Email",
"description": "Описание 1", "description": "Описание 1",
"description2": "Описание 2", "created_at": "Создан",
"status": "Статус" "status": "Статус"
}, },
"actions": ["view"], "actions": ["view"],
@ -22,15 +22,15 @@
"email", "description" "email", "description"
], ],
"data": [ "data": [
{"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "status": 1}, {"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","created_at":"2024-07-22 15:24:37", "status": 1},
{"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "status": 1}, {"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","created_at":"2024-04-22 15:56:37", "status": 1},
{"id": 3,"email":"fas3@mail.ru","description":"fafdgdssdfgdfs","description2":"ffdghdas", "status": 2}, {"id": 3,"email":"fas3@mail.ru","description":"fafdgdssdfgdfs","created_at":"2024-07-27 15:24:37", "status": 2},
{"id": 4,"email":"fas4@mail.ru","description":"fafddsfgsdvcbgdfs","description2":"ffdghdas", "status": 1}, {"id": 4,"email":"fas4@mail.ru","description":"fafddsfgsdvcbgdfs","created_at":"2024-07-04 15:24:37", "status": 1},
{"id": 5,"email":"fas5@mail.ru","description":"fafdgghjgfdfs","description2":"ffdghdas", "status": 1}, {"id": 5,"email":"fas5@mail.ru","description":"fafdgghjgfdfs","created_at":"2024-07-13 15:24:37", "status": 1},
{"id": 6,"email":"fas6@mail.ru","description":"fafddfgdhvgdfs","description2":"ffdghdas", "status": 1}, {"id": 6,"email":"fas6@mail.ru","description":"fafddfgdhvgdfs","created_at":"2024-07-20 15:24:37", "status": 1},
{"id": 7,"email":"fas7@mail.ru","description":"fafdfgnfdgdfs","description2":"ffdghdas", "status": 0}, {"id": 7,"email":"fas7@mail.ru","description":"fafdfgnfdgdfs","created_at":"2024-06-22 15:24:37", "status": 0},
{"id": 8,"email":"fas8@mail.ru","description":"fafdfghdfgdfs","description2":"ffdghdas", "status": 1}, {"id": 8,"email":"fas8@mail.ru","description":"fafdfghdfgdfs","created_at":"2023-12-12 15:12:37", "status": 1},
{"id": 12,"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","description2":"ffdgdfgsdfghdas", "status": 99}, {"id": 12,"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","created_at":"2024-03-11 17:24:37", "status": 99},
{"id": 13,"email":"dfsdfsddfd@mail.ru","description":"sdffhdfsdfshggsdfg","description2":"ffdgdsdffgsdfghdas", "status": 1} {"id": 13,"email":"dfsdfsddfd@mail.ru","description":"sdffhdfsdfshggsdfg","created_at":"2023-11-19 14:24:37", "status": 1}
] ]
} }

View File

@ -9,6 +9,10 @@ $table = new ListJsonTable($json);
//$table->columns([ //$table->columns([
$table->columns([ $table->columns([
[
'field' => 'created_at',
'format' => 'date:d-m-Y',
],
'status' => function ($cell) { 'status' => function ($cell) {
return getStatusLabel()[$cell]; return getStatusLabel()[$cell];
}, },

View File

@ -287,10 +287,21 @@ class ListJsonTable extends JasonTable
} }
} }
// public function columns(array $data): void
// {
// foreach ($data as $key => $value) {
// $this->beforePrintCell[$key] = $value;
// }
// }
public function columns(array $data): void public function columns(array $data): void
{ {
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$this->beforePrintCell[$key] = $value; foreach ($value as $currentKey => $currentValue) {
echo "<pre>";
print_r($currentValue);
// die();
}
} }
} }
} }

View File

@ -28,9 +28,9 @@ class ViewJsonTable extends JasonTable
$paramsStr = $this->createParams($this->data['meta']['params']); $paramsStr = $this->createParams($this->data['meta']['params']);
//Хук перед выводом ячейки //Хук перед выводом ячейки
if (isset($this->beforePrintTable)){ if (isset($this->beforePrintHook)){
$hook = $this->beforePrintTable; $hook = $this->beforePrintHook;
$this->html = $hook(); $this->html .= $hook();
} }
$this->html .= "<table $paramsStr>"; $this->html .= "<table $paramsStr>";
@ -65,8 +65,8 @@ class ViewJsonTable extends JasonTable
{ {
$this->html .= "</table>"; $this->html .= "</table>";
if(isset($this->afterPrintTable)){ if(isset($this->afterPrintHook)){
$hookAfter = $this->afterPrintTable; $hookAfter = $this->afterPrintHook;
$this->html .= $hookAfter(); $this->html .= $hookAfter();
} }
} }