New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow sorting of Tree like model list views #4811
Comments
Seems like we just need to remove this nautobot/nautobot/ipam/tables.py Line 376 in 70012f7
|
Given that prefixes are hierarchical, I'm not sure sorting makes a lot of sense (similar to #1854). Can you give an example of the type of sorting you'd expect to be able to do here? |
IIRC in #1854 we chose at the time to disable sorting on tree models primarily due to the odd visual representation of nested data and because we did not have the cycles in 2.0 to properly solve that. Let's use this issue to build a good story around the presentation and interaction with the Prefix hierarchy alone. I'm sure some of it will meaningfully carry over to other tree models like location, but there will be different use cases. To start, I can see two primary views into the prefix data.
As a user I would want a simple toggle between these two options in the list view. I'm certain we can get more advanced from there. In the first case, I care primary about drilling down into the data. In the second case, I care more about filtering and sorting, such as filtering by a location and then sorting by the role. |
2 would be what I was looking for, I asked chatgpt for some starter code to describe what I think makes sense class MyTable(tables.Table):
my_column = tables.TemplateColumn(template_name='my_column_template.html')
def __init__(self, *args, **kwargs):
super(MyTable, self).__init__(*args, **kwargs)
# Check if there's an explicit sorting
is_sorting = any(value for key, value in self.order_by_field.items() if value)
# Add context to all columns (or you can target a specific column)
for column in self.columns:
column.extra_context.update({'is_sorting': is_sorting}) Within the PREFIX_LINK = """
{% load helpers %}
{% if not is_sorting %}
{% for i in record.ancestors.count|as_range %}
<i class="mdi mdi-circle-small"></i>
{% endfor %}
{% endif %} |
For now, we will allow the sorting and when a user actually does sort, we will dynamically remove the hierarchy indentation. |
We had a request today regarding sorting in Locations, and I'm assuming it's missing due to the same reason. @lampwins do you want me to create a parallel issue? |
I don't think so. We would support sorting any column that it should be, in this model. |
Reopening this issue, needs to be implemented on the Prefix list view, and needs to be implemented when filtering a tree list view as well as sorting |
#5452 added sortability to the Prefix table. Remaining work now is to remove the indentation of entries whenever a filter is applied to any tree table. |
Environment
Steps to Reproduce
Expected Behavior
To sort based on the column header you created
Observed Behavior
No sorting
The text was updated successfully, but these errors were encountered: