Compare commits
No commits in common. "master" and "1.0.3" have entirely different histories.
@ -15,11 +15,11 @@
|
||||
"currentPage": "1",
|
||||
"showActionColumn": true,
|
||||
"showFiltersRow": true,
|
||||
"filter": true,
|
||||
"total": 10,
|
||||
"paginationPrefix": "/page",
|
||||
"params": {"class": "table table-bordered", "border": "1"}
|
||||
},
|
||||
"filters": ["email", "status"],
|
||||
"data": [
|
||||
{"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"},
|
||||
|
@ -68,9 +68,6 @@ $table->addColumn("Колонка 33", "k33", function ($id) {
|
||||
$table->addColumn("Колонка 34", "k34", function ($id) {
|
||||
return "some34";
|
||||
});
|
||||
$table->addAction(function($row, $url){
|
||||
return "<a href='mailto:". $row['email'] ."'>Написать</a>";
|
||||
});
|
||||
$table->create();
|
||||
$table->render();
|
||||
|
||||
|
@ -6,7 +6,6 @@ use Exception;
|
||||
use Itguild\Tables\ActionColumn\DeleteActionColumn;
|
||||
use Itguild\Tables\ActionColumn\EditActionColumn;
|
||||
use Itguild\Tables\ActionColumn\ViewActionColumn;
|
||||
use Itguild\Tables\Filter\InputTextFilter;
|
||||
use Itguild\Tables\traits\CreateParams;
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
|
||||
@ -71,7 +70,7 @@ class ListJsonTable extends JasonTable
|
||||
if ($this->showActionColumn) {
|
||||
$this->html .= "<th>Действия</th></th></tr>";
|
||||
}
|
||||
if ($this->showFiltersRow) {
|
||||
if($this->showFiltersRow){
|
||||
$this->getFilters($columnKeys);
|
||||
$this->html .= "</thead>";
|
||||
}
|
||||
@ -92,8 +91,8 @@ class ListJsonTable extends JasonTable
|
||||
}
|
||||
foreach ($row as $key => $cell) {
|
||||
if ($this->issetColumn($key) and $this->is_fillable($key)) {
|
||||
if ($this->beforePrintCell) {
|
||||
if ($key === "id" and $cell === 0) {
|
||||
if($this->beforePrintCell) {
|
||||
if ($key === "id" and $cell === 0){
|
||||
$cell = $this->count;
|
||||
}
|
||||
$cell = $this->getCustomCell($key, $cell);
|
||||
@ -104,7 +103,7 @@ class ListJsonTable extends JasonTable
|
||||
$this->getCustomColumns($row["id"] ?? null);
|
||||
if ($this->showActionColumn) {
|
||||
if (isset($row["id"])) {
|
||||
$actions = $this->getActions($row);
|
||||
$actions = $this->getActions($row["id"]);
|
||||
|
||||
$this->html .= "<td>$actions</td></tr>";
|
||||
} else {
|
||||
@ -115,7 +114,7 @@ class ListJsonTable extends JasonTable
|
||||
}
|
||||
}
|
||||
|
||||
public function addAction(string|\Closure $actionColumn): void
|
||||
public function addAction(string $actionColumn): void
|
||||
{
|
||||
$this->customActionsArray[] = $actionColumn;
|
||||
}
|
||||
@ -148,9 +147,9 @@ class ListJsonTable extends JasonTable
|
||||
|
||||
private function getCurrentFilter(string $column)
|
||||
{
|
||||
if (isset($this->beforePrintCell[$column]) and is_array($this->beforePrintCell[$column])) {
|
||||
if (is_array($this->beforePrintCell[$column])) {
|
||||
if (isset($this->beforePrintCell[$column]['filter'])) {
|
||||
if (isset($this->beforePrintCell[$column]['filter']) and is_array($this->beforePrintCell[$column]['filter'])) {
|
||||
if (is_array($this->beforePrintCell[$column]['filter'])) {
|
||||
return $this->beforePrintCell[$column]['filter'];
|
||||
}
|
||||
}
|
||||
@ -183,6 +182,7 @@ class ListJsonTable extends JasonTable
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function getColumnKeys(): array
|
||||
{
|
||||
$columnKeys = [];
|
||||
@ -253,16 +253,12 @@ class ListJsonTable extends JasonTable
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getActions(array $row): string
|
||||
private function getActions(int $id): string
|
||||
{
|
||||
$actions = "";
|
||||
foreach ($this->actionsArray as $item) {
|
||||
if (is_string($item)) {
|
||||
$objItem = new $item($this->baseUrl, $row['id']);
|
||||
$actions .= $objItem->fetch();
|
||||
} else {
|
||||
$actions .= $item($row, $this->baseUrl);
|
||||
}
|
||||
$objItem = new $item($this->baseUrl, $id);
|
||||
$actions .= $objItem->fetch();
|
||||
}
|
||||
|
||||
return $actions;
|
||||
@ -271,28 +267,20 @@ class ListJsonTable extends JasonTable
|
||||
private function getFilters(array $columnKeys): void
|
||||
{
|
||||
$this->html .= "<tr><form action='$this->baseUrl/search'>";
|
||||
foreach ($columnKeys as $key) {
|
||||
if ($this->issetFilter($key)) {
|
||||
foreach ($columnKeys as $key){
|
||||
if ($this->issetFilter($key)){
|
||||
$filter = $this->getCurrentFilter($key);
|
||||
$params = [
|
||||
$class = new $filter['class']([
|
||||
'param' => $filter['param'] ?? '',
|
||||
'name' => $key,
|
||||
'value' => $filter['value'] ?? '',
|
||||
];
|
||||
if ($filter) {
|
||||
$class = new $filter['class']($params);
|
||||
$this->html .= $class->fetch();
|
||||
} else {
|
||||
$class = new InputTextFilter($params);
|
||||
$this->html .= $class->fetch();
|
||||
}
|
||||
} else {
|
||||
]);
|
||||
$this->html .= $class->fetch();
|
||||
}
|
||||
else {
|
||||
$this->html .= "<td></td>";
|
||||
}
|
||||
}
|
||||
if ($this->showActionColumn) {
|
||||
$this->html .= "<td></td>";
|
||||
}
|
||||
$this->html .= "</form></tr>";
|
||||
}
|
||||
|
||||
@ -329,7 +317,7 @@ class ListJsonTable extends JasonTable
|
||||
$hookAfter = $this->afterPrintHook;
|
||||
$this->html .= $hookAfter($this->data['meta']);
|
||||
|
||||
if ($this->pagination && $this->data['data']) {
|
||||
if ($this->pagination) {
|
||||
$options = [
|
||||
'countItem' => $this->data['meta']['total'],
|
||||
'perPage' => $this->data['meta']['perPage'] ?? 10,
|
||||
|
Loading…
Reference in New Issue
Block a user