Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
5f46431d45 | |||
02a3e52b7d | |||
d747203d99 | |||
ad18d94489 | |||
453917ea1a | |||
1f2b93baf1 | |||
5cb5ac839d |
@ -15,11 +15,11 @@
|
|||||||
"currentPage": "1",
|
"currentPage": "1",
|
||||||
"showActionColumn": true,
|
"showActionColumn": true,
|
||||||
"showFiltersRow": true,
|
"showFiltersRow": 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"}
|
||||||
},
|
},
|
||||||
|
"filters": ["email", "status"],
|
||||||
"data": [
|
"data": [
|
||||||
{"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "created_at": "17.06.2024", "status": "1"},
|
{"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "created_at": "17.06.2024", "status": "1"},
|
||||||
{"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "created_at": "18.06.2024", "status": "1"},
|
{"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "created_at": "18.06.2024", "status": "1"},
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
ini_set("display_errors", true);
|
||||||
|
error_reporting(-1);
|
||||||
|
|
||||||
require_once "../vendor/autoload.php";
|
require_once "../vendor/autoload.php";
|
||||||
|
|
||||||
use Itguild\Tables\Filter\InputDateFilter;
|
use Itguild\Tables\Filter\InputDateFilter;
|
||||||
@ -65,6 +68,9 @@ $table->addColumn("Колонка 33", "k33", function ($id) {
|
|||||||
$table->addColumn("Колонка 34", "k34", function ($id) {
|
$table->addColumn("Колонка 34", "k34", function ($id) {
|
||||||
return "some34";
|
return "some34";
|
||||||
});
|
});
|
||||||
|
$table->addAction(function($row, $url){
|
||||||
|
return "<a href='mailto:". $row['email'] ."'>Написать</a>";
|
||||||
|
});
|
||||||
$table->create();
|
$table->create();
|
||||||
$table->render();
|
$table->render();
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ use Exception;
|
|||||||
use Itguild\Tables\ActionColumn\DeleteActionColumn;
|
use Itguild\Tables\ActionColumn\DeleteActionColumn;
|
||||||
use Itguild\Tables\ActionColumn\EditActionColumn;
|
use Itguild\Tables\ActionColumn\EditActionColumn;
|
||||||
use Itguild\Tables\ActionColumn\ViewActionColumn;
|
use Itguild\Tables\ActionColumn\ViewActionColumn;
|
||||||
|
use Itguild\Tables\Filter\InputTextFilter;
|
||||||
use Itguild\Tables\traits\CreateParams;
|
use Itguild\Tables\traits\CreateParams;
|
||||||
use JetBrains\PhpStorm\NoReturn;
|
use JetBrains\PhpStorm\NoReturn;
|
||||||
|
|
||||||
@ -64,13 +65,13 @@ class ListJsonTable extends JasonTable
|
|||||||
$this->html .= "<th>" . "ID" . "</th>";
|
$this->html .= "<th>" . "ID" . "</th>";
|
||||||
$columnKeys[] = "id";
|
$columnKeys[] = "id";
|
||||||
}
|
}
|
||||||
$columnKeys = $this->getColumnKeys();
|
$columnKeys = array_merge($columnKeys, $this->getColumnKeys());
|
||||||
$columnKeys = array_merge($columnKeys, $this->getCustomColumnKeys());
|
$columnKeys = array_merge($columnKeys, $this->getCustomColumnKeys());
|
||||||
$this->getCustomHeadColumn();
|
$this->getCustomHeadColumn();
|
||||||
if ($this->showActionColumn) {
|
if ($this->showActionColumn) {
|
||||||
$this->html .= "<th>Действия</th></th></tr>";
|
$this->html .= "<th>Действия</th></th></tr>";
|
||||||
}
|
}
|
||||||
if($this->showFiltersRow){
|
if ($this->showFiltersRow) {
|
||||||
$this->getFilters($columnKeys);
|
$this->getFilters($columnKeys);
|
||||||
$this->html .= "</thead>";
|
$this->html .= "</thead>";
|
||||||
}
|
}
|
||||||
@ -91,7 +92,10 @@ class ListJsonTable extends JasonTable
|
|||||||
}
|
}
|
||||||
foreach ($row as $key => $cell) {
|
foreach ($row as $key => $cell) {
|
||||||
if ($this->issetColumn($key) and $this->is_fillable($key)) {
|
if ($this->issetColumn($key) and $this->is_fillable($key)) {
|
||||||
if($this->beforePrintCell) {
|
if ($this->beforePrintCell) {
|
||||||
|
if ($key === "id" and $cell === 0) {
|
||||||
|
$cell = $this->count;
|
||||||
|
}
|
||||||
$cell = $this->getCustomCell($key, $cell);
|
$cell = $this->getCustomCell($key, $cell);
|
||||||
}
|
}
|
||||||
$this->html .= "<td style='" . $this->getStyleFromCustomColumn($key) . "'>" . $cell . "</td>";
|
$this->html .= "<td style='" . $this->getStyleFromCustomColumn($key) . "'>" . $cell . "</td>";
|
||||||
@ -100,7 +104,7 @@ class ListJsonTable extends JasonTable
|
|||||||
$this->getCustomColumns($row["id"] ?? null);
|
$this->getCustomColumns($row["id"] ?? null);
|
||||||
if ($this->showActionColumn) {
|
if ($this->showActionColumn) {
|
||||||
if (isset($row["id"])) {
|
if (isset($row["id"])) {
|
||||||
$actions = $this->getActions($row["id"]);
|
$actions = $this->getActions($row);
|
||||||
|
|
||||||
$this->html .= "<td>$actions</td></tr>";
|
$this->html .= "<td>$actions</td></tr>";
|
||||||
} else {
|
} else {
|
||||||
@ -111,7 +115,7 @@ class ListJsonTable extends JasonTable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addAction(string $actionColumn): void
|
public function addAction(string|\Closure $actionColumn): void
|
||||||
{
|
{
|
||||||
$this->customActionsArray[] = $actionColumn;
|
$this->customActionsArray[] = $actionColumn;
|
||||||
}
|
}
|
||||||
@ -144,9 +148,9 @@ class ListJsonTable extends JasonTable
|
|||||||
|
|
||||||
private function getCurrentFilter(string $column)
|
private function getCurrentFilter(string $column)
|
||||||
{
|
{
|
||||||
if (is_array($this->beforePrintCell[$column])) {
|
if (isset($this->beforePrintCell[$column]) and is_array($this->beforePrintCell[$column])) {
|
||||||
if (isset($this->beforePrintCell[$column]['filter'])) {
|
if (isset($this->beforePrintCell[$column]['filter'])) {
|
||||||
if (is_array($this->beforePrintCell[$column]['filter'])) {
|
if (isset($this->beforePrintCell[$column]['filter']) and is_array($this->beforePrintCell[$column]['filter'])) {
|
||||||
return $this->beforePrintCell[$column]['filter'];
|
return $this->beforePrintCell[$column]['filter'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +183,6 @@ class ListJsonTable extends JasonTable
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function getColumnKeys(): array
|
private function getColumnKeys(): array
|
||||||
{
|
{
|
||||||
$columnKeys = [];
|
$columnKeys = [];
|
||||||
@ -229,7 +232,7 @@ class ListJsonTable extends JasonTable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_array($this->beforePrintCell[$filter])) {
|
if (isset($this->beforePrintCell[$filter]) and is_array($this->beforePrintCell[$filter])) {
|
||||||
if (isset($this->beforePrintCell[$filter]['filter'])) {
|
if (isset($this->beforePrintCell[$filter]['filter'])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -250,12 +253,16 @@ class ListJsonTable extends JasonTable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getActions(int $id): string
|
private function getActions(array $row): string
|
||||||
{
|
{
|
||||||
$actions = "";
|
$actions = "";
|
||||||
foreach ($this->actionsArray as $item) {
|
foreach ($this->actionsArray as $item) {
|
||||||
$objItem = new $item($this->baseUrl, $id);
|
if (is_string($item)) {
|
||||||
$actions .= $objItem->fetch();
|
$objItem = new $item($this->baseUrl, $row['id']);
|
||||||
|
$actions .= $objItem->fetch();
|
||||||
|
} else {
|
||||||
|
$actions .= $item($row, $this->baseUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $actions;
|
return $actions;
|
||||||
@ -264,20 +271,28 @@ class ListJsonTable extends JasonTable
|
|||||||
private function getFilters(array $columnKeys): void
|
private function getFilters(array $columnKeys): void
|
||||||
{
|
{
|
||||||
$this->html .= "<tr><form action='$this->baseUrl/search'>";
|
$this->html .= "<tr><form action='$this->baseUrl/search'>";
|
||||||
foreach ($columnKeys as $key){
|
foreach ($columnKeys as $key) {
|
||||||
if ($this->issetFilter($key)){
|
if ($this->issetFilter($key)) {
|
||||||
$filter = $this->getCurrentFilter($key);
|
$filter = $this->getCurrentFilter($key);
|
||||||
$class = new $filter['class']([
|
$params = [
|
||||||
'param' => $filter['param'],
|
'param' => $filter['param'] ?? '',
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'value' => $filter['value']
|
'value' => $filter['value'] ?? '',
|
||||||
]);
|
];
|
||||||
$this->html .= $class->fetch();
|
if ($filter) {
|
||||||
}
|
$class = new $filter['class']($params);
|
||||||
else {
|
$this->html .= $class->fetch();
|
||||||
|
} else {
|
||||||
|
$class = new InputTextFilter($params);
|
||||||
|
$this->html .= $class->fetch();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
$this->html .= "<td></td>";
|
$this->html .= "<td></td>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($this->showActionColumn) {
|
||||||
|
$this->html .= "<td></td>";
|
||||||
|
}
|
||||||
$this->html .= "</form></tr>";
|
$this->html .= "</form></tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +329,7 @@ class ListJsonTable extends JasonTable
|
|||||||
$hookAfter = $this->afterPrintHook;
|
$hookAfter = $this->afterPrintHook;
|
||||||
$this->html .= $hookAfter($this->data['meta']);
|
$this->html .= $hookAfter($this->data['meta']);
|
||||||
|
|
||||||
if ($this->pagination) {
|
if ($this->pagination && $this->data['data']) {
|
||||||
$options = [
|
$options = [
|
||||||
'countItem' => $this->data['meta']['total'],
|
'countItem' => $this->data['meta']['total'],
|
||||||
'perPage' => $this->data['meta']['perPage'] ?? 10,
|
'perPage' => $this->data['meta']['perPage'] ?? 10,
|
||||||
|
Loading…
Reference in New Issue
Block a user