Compare commits
6 Commits
0.1.11
...
a2284e3bf2
Author | SHA1 | Date | |
---|---|---|---|
a2284e3bf2 | |||
9e7c83b680 | |||
b374744261 | |||
c6918c85b3 | |||
d98ddded07 | |||
1bd82eb40b |
@ -5,7 +5,7 @@
|
||||
"id": "ID",
|
||||
"email": "Email",
|
||||
"description": "Описание 1",
|
||||
"description2": "Описание 2",
|
||||
"created_at": "Создан",
|
||||
"status": "Статус"
|
||||
},
|
||||
"actions": ["view"],
|
||||
@ -22,15 +22,15 @@
|
||||
"email", "description"
|
||||
],
|
||||
"data": [
|
||||
{"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "status": 1},
|
||||
{"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 3,"email":"fas3@mail.ru","description":"fafdgdssdfgdfs","description2":"ffdghdas", "status": 2},
|
||||
{"id": 4,"email":"fas4@mail.ru","description":"fafddsfgsdvcbgdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 5,"email":"fas5@mail.ru","description":"fafdgghjgfdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 6,"email":"fas6@mail.ru","description":"fafddfgdhvgdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 7,"email":"fas7@mail.ru","description":"fafdfgnfdgdfs","description2":"ffdghdas", "status": 0},
|
||||
{"id": 8,"email":"fas8@mail.ru","description":"fafdfghdfgdfs","description2":"ffdghdas", "status": 1},
|
||||
{"id": 12,"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","description2":"ffdgdfgsdfghdas", "status": 99},
|
||||
{"id": 13,"email":"dfsdfsddfd@mail.ru","description":"sdffhdfsdfshggsdfg","description2":"ffdgdsdffgsdfghdas", "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","created_at":"2024-04-22 15:56:37", "status": 1},
|
||||
{"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","created_at":"2024-07-04 15:24:37", "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","created_at":"2024-07-20 15:24:37", "status": 1},
|
||||
{"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","created_at":"2023-12-12 15:12:37", "status": 1},
|
||||
{"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","created_at":"2023-11-19 14:24:37", "status": 1}
|
||||
]
|
||||
}
|
@ -9,6 +9,10 @@ $table = new ListJsonTable($json);
|
||||
|
||||
//$table->columns([
|
||||
$table->columns([
|
||||
[
|
||||
'field' => 'created_at',
|
||||
'format' => 'date:d-m-Y',
|
||||
],
|
||||
'status' => function ($cell) {
|
||||
return getStatusLabel()[$cell];
|
||||
},
|
||||
|
@ -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) {
|
||||
|
@ -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 .= "<td>" . $cell . "</td>";
|
||||
@ -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
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$this->beforePrintCell[$key] = $value;
|
||||
foreach ($value as $currentKey => $currentValue) {
|
||||
echo "<pre>";
|
||||
print_r($currentValue);
|
||||
// die();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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'];
|
||||
@ -28,9 +28,9 @@ class ViewJsonTable extends JasonTable
|
||||
$paramsStr = $this->createParams($this->data['meta']['params']);
|
||||
|
||||
//Хук перед выводом ячейки
|
||||
if (isset($this->beforePrintTable)){
|
||||
$hook = $this->beforePrintTable;
|
||||
$this->html = $hook();
|
||||
if (isset($this->beforePrintHook)){
|
||||
$hook = $this->beforePrintHook;
|
||||
$this->html .= $hook();
|
||||
}
|
||||
|
||||
$this->html .= "<table $paramsStr>";
|
||||
@ -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 .= "<tr><th>" . $row . "</th><td>" . $this->dataJson[$key] . "</td></tr>";
|
||||
@ -65,8 +65,8 @@ class ViewJsonTable extends JasonTable
|
||||
{
|
||||
$this->html .= "</table>";
|
||||
|
||||
if(isset($this->afterPrintTable)){
|
||||
$hookAfter = $this->afterPrintTable;
|
||||
if(isset($this->afterPrintHook)){
|
||||
$hookAfter = $this->afterPrintHook;
|
||||
$this->html .= $hookAfter();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user