Добавлено логирование сортировки для отладки
This commit is contained in:
@@ -103,7 +103,7 @@ $app->post('/api/table/data', function (Request $request, Response $response) us
|
|||||||
$columns = $payload['columns'] ?? [];
|
$columns = $payload['columns'] ?? [];
|
||||||
|
|
||||||
// ✅ Логирование для отладки
|
// ✅ Логирование для отладки
|
||||||
error_log("Data request: page=$page, pageSize=$pageSize, filters=" . json_encode($filters));
|
error_log("Data request: page=$page, pageSize=$pageSize, filters=" . json_encode($filters) . ", sort=" . json_encode($sort));
|
||||||
|
|
||||||
$pdo = $container->get('db');
|
$pdo = $container->get('db');
|
||||||
$ds = new \App\DataService($pdo);
|
$ds = new \App\DataService($pdo);
|
||||||
|
|||||||
@@ -37,12 +37,22 @@ class DataService
|
|||||||
$whereSql = $whereParts ? 'WHERE ' . implode(' AND ', $whereParts) : '';
|
$whereSql = $whereParts ? 'WHERE ' . implode(' AND ', $whereParts) : '';
|
||||||
|
|
||||||
$orderSql = '';
|
$orderSql = '';
|
||||||
if ($sort && !empty($sort['field']) && in_array($sort['field'], $colNames, true)) {
|
error_log("=== SORT DEBUG (fetchData) ===");
|
||||||
$dir = strtoupper($sort['dir'] ?? 'ASC');
|
error_log("Sort param: " . json_encode($sort));
|
||||||
if (!in_array($dir, ['ASC', 'DESC'], true)) {
|
error_log("Column names: " . implode(', ', array_slice($colNames, 0, 5)) . "...");
|
||||||
$dir = 'ASC';
|
if ($sort && !empty($sort['field'])) {
|
||||||
|
$fieldExists = in_array($sort['field'], $colNames, true);
|
||||||
|
error_log("Field '{$sort['field']}' exists: " . ($fieldExists ? 'YES' : 'NO'));
|
||||||
|
if ($fieldExists) {
|
||||||
|
$dir = strtoupper($sort['dir'] ?? 'ASC');
|
||||||
|
if (!in_array($dir, ['ASC', 'DESC'], true)) {
|
||||||
|
$dir = 'ASC';
|
||||||
|
}
|
||||||
|
$orderSql = "ORDER BY `{$sort['field']}` $dir";
|
||||||
|
error_log("ORDER SQL: $orderSql");
|
||||||
}
|
}
|
||||||
$orderSql = "ORDER BY `{$sort['field']}` $dir";
|
} else {
|
||||||
|
error_log("No sort applied");
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT $selectList
|
$sql = "SELECT $selectList
|
||||||
@@ -50,6 +60,7 @@ class DataService
|
|||||||
$whereSql
|
$whereSql
|
||||||
$orderSql
|
$orderSql
|
||||||
LIMIT :limit OFFSET :offset";
|
LIMIT :limit OFFSET :offset";
|
||||||
|
error_log("Final SQL: " . preg_replace('/\s+/', ' ', $sql));
|
||||||
|
|
||||||
$stmt = $this->pdo->prepare($sql);
|
$stmt = $this->pdo->prepare($sql);
|
||||||
foreach ($params as $k => $v) {
|
foreach ($params as $k => $v) {
|
||||||
|
|||||||
Reference in New Issue
Block a user