From fcfd785b04aa5a2476a958b722ec66a5417da28e Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Thu, 22 Jan 2026 11:18:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0:=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2=D0=B0?= =?UTF-8?q?=20sort=20=D0=BE=D1=82=20Tabulator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tabulator отправляет sort как массив [{"field":..., "dir":...}], а код ожидал объект {"field":..., "dir":...}. Добавлена конвертация. Co-Authored-By: Claude Opus 4.5 --- src/DataService.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/DataService.php b/src/DataService.php index 6d89a9d..c5b49ef 100644 --- a/src/DataService.php +++ b/src/DataService.php @@ -37,24 +37,18 @@ class DataService $whereSql = $whereParts ? 'WHERE ' . implode(' AND ', $whereParts) : ''; $orderSql = ''; - // Логируем в файл - $logFile = __DIR__ . '/../debug.log'; - file_put_contents($logFile, date('Y-m-d H:i:s') . " === SORT DEBUG ===\n", FILE_APPEND); - file_put_contents($logFile, "Sort param: " . json_encode($sort) . "\n", FILE_APPEND); - file_put_contents($logFile, "Column names count: " . count($colNames) . "\n", FILE_APPEND); - if ($sort && !empty($sort['field'])) { - $fieldExists = in_array($sort['field'], $colNames, true); - file_put_contents($logFile, "Field '{$sort['field']}' exists: " . ($fieldExists ? 'YES' : 'NO') . "\n", FILE_APPEND); - if ($fieldExists) { - $dir = strtoupper($sort['dir'] ?? 'ASC'); - if (!in_array($dir, ['ASC', 'DESC'], true)) { - $dir = 'ASC'; - } - $orderSql = "ORDER BY `{$sort['field']}` $dir"; - file_put_contents($logFile, "ORDER SQL: $orderSql\n", FILE_APPEND); + + // ✅ Если sort пришёл как массив [{"field":..., "dir":...}], берём первый элемент + if ($sort && is_array($sort) && isset($sort[0])) { + $sort = $sort[0]; + } + + if ($sort && !empty($sort['field']) && in_array($sort['field'], $colNames, true)) { + $dir = strtoupper($sort['dir'] ?? 'ASC'); + if (!in_array($dir, ['ASC', 'DESC'], true)) { + $dir = 'ASC'; } - } else { - file_put_contents($logFile, "No sort (sort is null or field empty)\n", FILE_APPEND); + $orderSql = "ORDER BY `{$sort['field']}` $dir"; } $sql = "SELECT $selectList @@ -697,6 +691,12 @@ private function formatRowData(array $rowData): string $whereSql = $whereParts ? 'WHERE ' . implode(' AND ', $whereParts) : ''; $orderSql = ''; + + // ✅ Если sort пришёл как массив [{"field":..., "dir":...}], берём первый элемент + if ($sort && is_array($sort) && isset($sort[0])) { + $sort = $sort[0]; + } + if ($sort && !empty($sort['field']) && in_array($sort['field'], $colNames, true)) { $dir = strtoupper($sort['dir'] ?? 'ASC'); if (!in_array($dir, ['ASC', 'DESC'], true)) {