Sorting search results by Object column does not work #7908

Closed
opened 2025-12-29 20:29:46 +01:00 by adam · 2 comments
Owner

Originally created by @decoupca on GitHub (Apr 14, 2023).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.4.8

Python version

3.8

Steps to Reproduce

  1. Run any search that returns more than 1 result
  2. Click the Object header to sort

Expected Behavior

Results table should be sorted lexicographically by object name.

Observed Behavior

Results table is sorted by some other unclear criteria

Originally created by @decoupca on GitHub (Apr 14, 2023). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.4.8 ### Python version 3.8 ### Steps to Reproduce 1. Run any search that returns more than 1 result 2. Click the Object header to sort ### Expected Behavior Results table should be sorted lexicographically by object name. ### Observed Behavior Results table is sorted by some other unclear criteria
adam added the type: bugstatus: accepted labels 2025-12-29 20:29:46 +01:00
adam closed this issue 2025-12-29 20:29:46 +01:00
Author
Owner

@decoupca commented on GitHub (Apr 14, 2023):

I worked on this while resolving #11383. I couldn't find an accessor string that works across all object types. In other words, I couldn't find a single common name attribute for all object types. The object's name attribute varies by type, so a single sort_by accessor doesn't seem possible. Unless I missed an attribute that already exists, it looks like the solution would entail creating a universal name attribute common across all object types that we could use as the accessor for sort_by.

@decoupca commented on GitHub (Apr 14, 2023): I worked on this while resolving #11383. I couldn't find an accessor string that works across all object types. In other words, I couldn't find a single common name attribute for all object types. The object's name attribute varies by type, so a single `sort_by` accessor doesn't seem possible. Unless I missed an attribute that already exists, it looks like the solution would entail creating a universal name attribute common across all object types that we could use as the accessor for `sort_by`.
Author
Owner

@decoupca commented on GitHub (Apr 24, 2023):

Took another look at this, still can't find an accessor that will work across all object types. Doesn't look like django_tables2 supports anything like a dynamic accessor, except when working with querysets. AFAICT global search doesn't return a queryset, and even if it did, it's not clear that would solve the problem, as we might end up in the same situation, trying to order on different properties based on object type.

The most straightforward solution I see is to add the object's name to a property of CachedValue and point the order_by arg to that. I can take a stab at implementing this if a maintainer can give me guidance on the approach we want to take.

@decoupca commented on GitHub (Apr 24, 2023): Took another look at this, still can't find an accessor that will work across all object types. Doesn't look like `django_tables2` supports anything like a dynamic accessor, except when working with querysets. AFAICT global search doesn't return a queryset, and even if it did, it's not clear that would solve the problem, as we might end up in the same situation, trying to order on different properties based on object type. The most straightforward solution I see is to add the object's name to a property of `CachedValue` and point the `order_by` arg to that. I can take a stab at implementing this if a maintainer can give me guidance on the approach we want to take.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7908