Skip to content

fix(search): order default lists by first visible column again - #25221

Open
iPaulis wants to merge 1 commit into
glpi-project:11.0/bugfixesfrom
iPaulis:fix/25208-default-sort
Open

fix(search): order default lists by first visible column again#25221
iPaulis wants to merge 1 commit into
glpi-project:11.0/bugfixesfrom
iPaulis:fix/25208-default-sort

Conversation

@iPaulis

@iPaulis iPaulis commented Aug 22, 2026

Copy link
Copy Markdown

Fix default sorting: order lists by first visible column again

Fixes #25208

Problem

Since GLPI 11, default list views (Users, Computers, Groups, Entities, Locations, Change, Problem, …) are silently sorted by the id column instead of the first visible column when the user has not explicitly chosen a sort. The list looks "unsorted" / ordered by an invisible column.

In GLPI 10 the same lists were sorted by the first visible column by default. Clicking a column header still sorts correctly — the bug only affects the default case (fresh session / no stored sort).

Root cause

In SearchEngine::prepareDataForSearch():

$data['search'] = $p;                                   // (1) snapshot — sort is [0] here
// ...
$data['toview'] = SearchOption::getDefaultToView($itemtype, $params);
if ($p['sort'] === [0]) {
    $p['sort'] = [array_values($data['toview'])[0]];    // (2) only $p is updated
}

$data['search'] is copied before the default sort substitution, so the later $p['sort'] assignment is never propagated back. SQLProvider::constructSQL() then reads $data['search']['sort'] (still [0]), which never matches any element of tocompute in the ORDER BY loop, so the fallback ORDER BY id is used.

Change

One-line synchronization of the corrected default sort back into $data['search']:

$data['toview'] = SearchOption::getDefaultToView($itemtype, $params);
if ($p['sort'] === [0]) {
    $p['sort'] = [array_values($data['toview'])[0]];
    $data['search']['sort'] = $p['sort'];
}

Verification

  • Reproduced on GLPI 11.0.8 and confirmed present on 11.0/bugfixes.
  • With no explicit sort, the generated SQL is now ORDER BY ITEM_<ItemType>_<first visible searchopt> ASC (e.g. ORDER BY name ASC for Users, ITEM_Computer_1, ITEM_Group_1, ITEM_Entity_1, ITEM_Location_1, ITEM_Change_2, …) instead of ORDER BY id.
  • Explicit sort behavior is unchanged.
  • php -l clean.

In SearchEngine::prepareDataForSearch(), when the user has not set an
explicit sort, the default sort is set to the first visible column on
$p['sort'] — but $data['search'] was snapshotted earlier, so the
changed sort was never propagated back to it. SQLProvider::constructSQL()
then read $data['search']['sort'] (still [0]), which never matched any
visible column, so the generated ORDER BY fell back to the hidden id
column.

Synchronize $data['search']['sort'] with the corrected default so the
provider orders by the first visible column, restoring the GLPI 10
behavior. Fixes glpi-project#25208.
Copilot AI lite review requested due to automatic review settings August 22, 2026 02:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default sorting broken in GLPI 11: lists sorted by hidden id column instead of first visible column

2 participants