filter class

This commit is contained in:
2024-08-23 14:52:22 +03:00
parent 77a306a0f6
commit b4dc2f6ab1
8 changed files with 118 additions and 59 deletions

View File

@ -6,6 +6,8 @@ use Exception;
use Itguild\Tables\ActionColumn\DeleteActionColumn;
use Itguild\Tables\ActionColumn\EditActionColumn;
use Itguild\Tables\ActionColumn\ViewActionColumn;
use Itguild\Tables\Filter\InputFilter;
use Itguild\Tables\Filter\SelectFilter;
use Itguild\Tables\traits\CreateParams;
use JetBrains\PhpStorm\NoReturn;
@ -21,7 +23,8 @@ class ListJsonTable extends JasonTable
private bool $pagination = true;
private bool $showActionColumn = true;
private bool|array $filters = false;
private bool $showFiltersRow = true;
private bool|array $filters = [];
private array $actionsArray = [];
private array $customActionsArray = [];
@ -35,7 +38,8 @@ class ListJsonTable extends JasonTable
$this->baseUrl = $this->data['meta']['baseUrl'] ?? '';
$this->pagination = $this->data['meta']['pagination'] ?? true;
$this->showActionColumn = $this->data['meta']['showActionColumn'] ?? true;
$this->filters = $this->data['filters'] ?? false;
$this->showFiltersRow = $this->data['meta']['showFiltersRow'] ?? true;
$this->filters = $this->data['filters'] ?? [];
$this->beforePrintHook = function () {
};
$this->afterPrintHook = function () {
@ -66,10 +70,14 @@ class ListJsonTable extends JasonTable
$columnKeys = array_merge($columnKeys, $this->getCustomColumnKeys());
$this->getCustomHeadColumn();
if ($this->showActionColumn) {
$this->html .= "<th>Действия</th></th></tr></thead>";
$this->html .= "<th>Действия</th></th></tr>";
}
if ($this->filters) {
// if ($this->filters) {
// $this->getFilters($columnKeys);
// }
if($this->showFiltersRow){
$this->getFilters($columnKeys);
$this->html .= "</thead>";
}
}
@ -139,6 +147,15 @@ class ListJsonTable extends JasonTable
$this->actionsArray = array_merge($this->actionsArray, $this->customActionsArray);
}
private function getCurrentFilter(string $filter): false|string
{
return match ($filter) {
'input' => InputFilter::class,
'select' => SelectFilter::class,
default => false,
};
}
public function getCustomColumns($id = null): void
{
foreach ($this->customColumnsArray as $item) {
@ -251,7 +268,15 @@ class ListJsonTable extends JasonTable
$this->html .= "<tr><form action='$this->baseUrl/search'>";
foreach ($columnKeys as $key){
if ($this->issetFilter($key)){
$this->html .= "<td><input type='" . $this->getFilterFromCustomColumn($key) . "' name='$key'></td>";
// $this->html .= "<td><input type='" . $this->getFilterFromCustomColumn($key) . "' name='$key'></td>";
$tag = $this->getTagFromCustomColumn($key);
$item = $this->getCurrentFilter($tag);
$objItem = new $item([
'data' => $this->getFilterFromCustomColumn($key),
'name' => $key
// 'value' => $this->getFilterFromCustomColumn($key)
]);
$this->html .= $objItem->fetch();
}
else {
$this->html .= "<td></td>";
@ -266,6 +291,7 @@ class ListJsonTable extends JasonTable
public function create(): void
{
$this->setActions();
// $this->setFilters();
$this->beginTable();
$this->createThead();
$this->createTbody();