filter beta

This commit is contained in:
Билай Станислав 2024-08-01 12:28:21 +03:00
parent 320e1070ba
commit b7fe32b91d
4 changed files with 54 additions and 7 deletions

View File

@ -11,6 +11,7 @@
"perPage": "5", "perPage": "5",
"currentPage": "1", "currentPage": "1",
"showActionColumn": true, "showActionColumn": true,
"filter": true,
"total": 10, "total": 10,
"paginationPrefix": "/page", "paginationPrefix": "/page",
"params": {"class": "table table-bordered", "border": "1"} "params": {"class": "table table-bordered", "border": "1"}

47
src/Filter.php Normal file
View File

@ -0,0 +1,47 @@
<?php
namespace Itguild\Tables;
class Filter
{
private array $columnsForFilter;
private string $html = "";
private string $baseUrl;
public function __construct(array $columns, string $baseUrl)
{
$this->columnsForFilter = $columns;
$this->baseUrl = $baseUrl;
}
public function create(): void
{
$this->html = str_replace('{action_link}', $this->baseUrl, $this->getTemplate());
$this->html = str_replace('{column}', 'id', $this->html);
}
public function render(): void
{
echo $this->html;
}
public function fetch(): string
{
return $this->html;
}
public function getColumnsForFilter(): array
{
return $this->columnsForFilter;
}
public function getTemplate(): string
{
return '<nav aria-label="Filters example">
<form action="{action_link}">
<input type="text" name="{column}">
</nav>';
}
}

View File

@ -26,6 +26,7 @@ class ListJsonTable
private bool $pagination = true; private bool $pagination = true;
private bool $showActionColumn = true; private bool $showActionColumn = true;
private bool $filter = true;
private array $actionsArray = []; private array $actionsArray = [];
private array $customActionsArray = []; private array $customActionsArray = [];
@ -39,6 +40,7 @@ class ListJsonTable
$this->baseUrl = $this->data['meta']['baseUrl'] ?? ''; $this->baseUrl = $this->data['meta']['baseUrl'] ?? '';
$this->pagination = $this->data['meta']['pagination'] ?? true; $this->pagination = $this->data['meta']['pagination'] ?? true;
$this->showActionColumn = $this->data['meta']['showActionColumn'] ?? true; $this->showActionColumn = $this->data['meta']['showActionColumn'] ?? true;
$this->filter = $this->data['meta']['filter'] ?? true;
$this->beforePrintHook = function () { $this->beforePrintHook = function () {
}; };
$this->afterPrintHook = function () { $this->afterPrintHook = function () {
@ -86,6 +88,10 @@ class ListJsonTable
{ {
if ($this->data['data']) { if ($this->data['data']) {
// if($this->filter)
// {
//
// }
$this->count = $this->data["meta"]["perPage"] * ($this->data['meta']["currentPage"] - 1); $this->count = $this->data["meta"]["perPage"] * ($this->data['meta']["currentPage"] - 1);
foreach ($this->data['data'] as $row) { foreach ($this->data['data'] as $row) {
$this->html .= "<tr>"; $this->html .= "<tr>";

View File

@ -17,8 +17,6 @@ class Pagination
private string $baseUrl; private string $baseUrl;
// public function __construct($countItem, $perPage, $currentPage, $baseUrl)
/** /**
* @throws Exception * @throws Exception
*/ */
@ -59,11 +57,6 @@ class Pagination
return $this->html; return $this->html;
} }
public function hookBefore(): void
{
}
private function getTemplate(): string private function getTemplate(): string
{ {
return '<nav aria-label="Page navigation example"> return '<nav aria-label="Page navigation example">