custom action
This commit is contained in:
parent
ad18d94489
commit
d747203d99
@ -68,6 +68,9 @@ $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();
|
||||
|
||||
|
@ -104,7 +104,7 @@ class ListJsonTable extends JasonTable
|
||||
$this->getCustomColumns($row["id"] ?? null);
|
||||
if ($this->showActionColumn) {
|
||||
if (isset($row["id"])) {
|
||||
$actions = $this->getActions($row["id"]);
|
||||
$actions = $this->getActions($row);
|
||||
|
||||
$this->html .= "<td>$actions</td></tr>";
|
||||
} else {
|
||||
@ -115,7 +115,7 @@ class ListJsonTable extends JasonTable
|
||||
}
|
||||
}
|
||||
|
||||
public function addAction(string $actionColumn): void
|
||||
public function addAction(string|\Closure $actionColumn): void
|
||||
{
|
||||
$this->customActionsArray[] = $actionColumn;
|
||||
}
|
||||
@ -183,7 +183,6 @@ class ListJsonTable extends JasonTable
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function getColumnKeys(): array
|
||||
{
|
||||
$columnKeys = [];
|
||||
@ -254,12 +253,16 @@ class ListJsonTable extends JasonTable
|
||||
return false;
|
||||
}
|
||||
|
||||
private function getActions(int $id): string
|
||||
private function getActions(array $row): string
|
||||
{
|
||||
$actions = "";
|
||||
foreach ($this->actionsArray as $item) {
|
||||
$objItem = new $item($this->baseUrl, $id);
|
||||
if (is_string($item)) {
|
||||
$objItem = new $item($this->baseUrl, $row['id']);
|
||||
$actions .= $objItem->fetch();
|
||||
} else {
|
||||
$actions .= $item($row, $this->baseUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return $actions;
|
||||
@ -279,13 +282,11 @@ class ListJsonTable extends JasonTable
|
||||
if ($filter) {
|
||||
$class = new $filter['class']($params);
|
||||
$this->html .= $class->fetch();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$class = new InputTextFilter($params);
|
||||
$this->html .= $class->fetch();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$this->html .= "<td></td>";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user