dynamic table

This commit is contained in:
root
2026-01-10 19:43:04 +03:00
parent 5f5a28e292
commit d27f66953c
9 changed files with 387 additions and 251 deletions
+46 -10
View File
@@ -17,11 +17,11 @@ class Clients extends BaseController
public function index()
{
$config = $this->getTableConfig();
$data = $this->prepareTableData($config);
$data['title'] = 'Клиенты';
return $this->renderTwig($config['viewPath'], $data);
return $this->renderTwig('@Clients/index', [
'title' => 'Клиенты',
'tableHtml' => $this->renderTable($config),
]);
}
/**
@@ -32,6 +32,8 @@ class Clients extends BaseController
$organizationId = session()->get('active_org_id');
return [
'id' => 'clients-table',
'url' => '/clients/table',
'model' => $this->clientModel,
'columns' => [
'name' => ['label' => 'Имя / Название', 'width' => '40%'],
@@ -42,17 +44,51 @@ class Clients extends BaseController
'sortable' => ['name', 'email', 'phone', 'created_at'],
'defaultSort' => 'name',
'order' => 'asc',
'viewPath' => '@Clients/index',
'partialPath' => '@Clients/_table',
'itemsKey' => 'clients',
'scope' => function ($builder) use ($organizationId) {
'actions' => ['label' => 'Действия', 'width' => '15%'],
'actionsConfig' => [
[
'label' => '',
'url' => '/clients/edit/{id}',
'icon' => 'fa-solid fa-pen',
'class' => 'btn-outline-primary',
'title' => 'Редактировать'
],
[
'label' => '',
'url' => '/clients/delete/{id}',
'icon' => 'fa-solid fa-trash',
'class' => 'btn-outline-danger',
'title' => 'Удалить'
]
],
'emptyMessage' => 'Клиентов пока нет',
'emptyIcon' => 'fa-solid fa-users',
'emptyActionUrl' => base_url('/clients/new'),
'emptyActionLabel'=> 'Добавить клиента',
'emptyActionIcon' => 'fa-solid fa-plus',
'scope' => function ($builder) use ($organizationId) {
$builder->where('organization_id', $organizationId);
},
];
}
public function table()
{
return parent::table();
$isPartial = $this->request->getGet('format') === 'partial' || $this->isAjax();
if ($isPartial) {
// AJAX — только tbody + tfoot
return $this->renderTable(null, true);
}
// Прямой запрос — полная страница
$config = $this->getTableConfig();
$tableHtml = $this->renderTable($config, false);
return $this->renderTwig('@Clients/index', [
'title' => $config['pageTitle'] ?? 'Клиенты',
'tableHtml' => $tableHtml,
]);
}
public function new()