column format

This commit is contained in:
2024-08-08 14:21:47 +03:00
parent d98ddded07
commit 02fa193652
8 changed files with 104 additions and 15 deletions

View File

@ -62,7 +62,7 @@ class ListJsonTable extends JasonTable
$this->html .= "<th>" . "ID" . "</th>";
$columnKeys[] = "id";
}
$columnKeys = $this->getColumnKeys($columnKeys);
$columnKeys = $this->getColumnKeys();
$columnKeys = array_merge($columnKeys, $this->getCustomColumnKeys());
$this->getCustomHeadColumn();
if ($this->showActionColumn) {
@ -78,6 +78,8 @@ class ListJsonTable extends JasonTable
if ($this->data['data']) {
$this->count = $this->data["meta"]["perPage"] * ($this->data['meta']["currentPage"] - 1);
foreach ($this->data['data'] as $row) {
//сортируем колнки согласно массиву колонок из json
$row = array_merge(array_flip($this->getFillableColumns()), $row);
$this->html .= "<tr>";
$this->count += 1;
$id = $row["id"] ?? $this->count;
@ -161,8 +163,9 @@ class ListJsonTable extends JasonTable
return $keys;
}
private function getColumnKeys(array $columnKeys): array
private function getColumnKeys(): array
{
$columnKeys = [];
foreach ($this->data['meta']['columns'] as $key => $column) {
if ($this->is_fillable($key)) {
$this->html .= "<th>" . $column . "</th>";
@ -172,6 +175,17 @@ class ListJsonTable extends JasonTable
return $columnKeys;
}
private function getFillableColumns(): array
{
$columnKeys = [];
foreach ($this->data['meta']['columns'] as $key => $column) {
if ($this->is_fillable($key)) {
$columnKeys[] = $key;
}
}
return $columnKeys;
}
private function issetColumn($column): bool
{
if (isset($this->data['meta']['columns'])) {