pagination
This commit is contained in:
parent
1714afcf3f
commit
647fe34d11
@ -6,11 +6,11 @@
|
||||
"description": "Описание 1",
|
||||
"description2": "Описание 2"
|
||||
},
|
||||
"params": {"class": "table table-bordered", "border": "1"}
|
||||
},
|
||||
"paginationParams": {
|
||||
"pagination": true,
|
||||
"perPage": "5",
|
||||
"currentPage": "1"
|
||||
"currentPage": "1",
|
||||
"total": 10,
|
||||
"params": {"class": "table table-bordered", "border": "1"}
|
||||
},
|
||||
"data": [
|
||||
{"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas"},
|
||||
@ -21,6 +21,7 @@
|
||||
{"email":"fas6@mail.ru","description":"fafddfgdhvgdfs","description2":"ffdghdas"},
|
||||
{"email":"fas7@mail.ru","description":"fafdfgnfdgdfs","description2":"ffdghdas"},
|
||||
{"email":"fas8@mail.ru","description":"fafdfghdfgdfs","description2":"ffdghdas"},
|
||||
{"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","description2":"ffdgdfgsdfghdas"}
|
||||
{"email":"dfdfd@mail.ru","description":"sdffhdfhggsdfg","description2":"ffdgdfgsdfghdas"},
|
||||
{"email":"dfsdfsddfd@mail.ru","description":"sdffhdfsdfshggsdfg","description2":"ffdgdsdffgsdfghdas"}
|
||||
]
|
||||
}
|
@ -23,6 +23,8 @@ class ListJsonTable
|
||||
private string $baseUrl;
|
||||
private array $data;
|
||||
|
||||
private bool $pagination = true;
|
||||
|
||||
private array $actionsArray = [];
|
||||
private array $customActionsArray = [];
|
||||
|
||||
@ -32,6 +34,7 @@ class ListJsonTable
|
||||
$this->json = $json;
|
||||
$this->data = json_decode($this->json, true);
|
||||
$this->baseUrl = $this->data['meta']['baseUrl'] ?? '';
|
||||
$this->pagination = $this->data['meta']['pagination'] ?? true;
|
||||
$this->beforePrintHook = function () {
|
||||
};
|
||||
$this->afterPrintHook = function () {
|
||||
@ -80,7 +83,8 @@ class ListJsonTable
|
||||
foreach ($this->data['data'] as $col) {
|
||||
$this->html .= "<tr>";
|
||||
$this->count += 1;
|
||||
$this->html .= '<td><a href=' . $this->baseUrl . "/" . $col["id"] . '>' . $this->count . '</a></td>';
|
||||
$id = $col["id"] ?? $this->count;
|
||||
$this->html .= '<td><a href=' . $this->baseUrl . "/" . $id . '>' . $id . '</a></td>';
|
||||
foreach ($col as $key => $row) {
|
||||
if ($this->issetColumn($key) and $this->is_fillable($key)) {
|
||||
if ($this->beforePrintCell) {
|
||||
@ -191,13 +195,19 @@ class ListJsonTable
|
||||
public function endTable(): void
|
||||
{
|
||||
$this->html .= "</table>";
|
||||
// $pagination = new Pagination($this->data['meta']['total'], $this->data['meta']['perPage'], $this->data['meta']['currentPage'], $this->baseUrl);
|
||||
$pagination = new Pagination(count($this->data['data']), $this->data['paginationParams'], $this->baseUrl);
|
||||
var_dump(count($this->data['data']));
|
||||
$pagination->create();
|
||||
$this->html .= $pagination->fetch();
|
||||
$hookAfter = $this->afterPrintHook;
|
||||
$this->html .= $hookAfter($this->data['meta']);
|
||||
|
||||
if ($this->pagination){
|
||||
$pagination = new Pagination(
|
||||
$this->data['meta']['total'],
|
||||
$this->data['meta']['perPage'],
|
||||
$this->data['meta']['currentPage'],
|
||||
$this->baseUrl
|
||||
);
|
||||
$pagination->create();
|
||||
$this->html .= $pagination->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function render(): void
|
||||
|
@ -14,12 +14,12 @@ class Pagination
|
||||
|
||||
private string $baseUrl;
|
||||
|
||||
// public function __construct($countItem, $perPage, $currentPage, $baseUrl)
|
||||
public function __construct(int $countItem, array $params, string $baseUrl)
|
||||
public function __construct($countItem, $perPage, $currentPage, $baseUrl)
|
||||
// public function __construct(int $countItem, array $params, string $baseUrl)
|
||||
{
|
||||
$this->countItem = $countItem;
|
||||
$this->perPage = $params['perPage'];
|
||||
$this->currentPage = $params['currentPage'];
|
||||
$this->perPage = $perPage;
|
||||
$this->currentPage = $currentPage;
|
||||
$this->baseUrl = $baseUrl;
|
||||
|
||||
$this->countPages = ceil($this->countItem / $this->perPage);
|
||||
|
Loading…
Reference in New Issue
Block a user