diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index 978c860ea..1e718a226 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -1,5 +1,13 @@ # NetBox v3.0 +## v3.0.6 (FUTURE) + +### Bug Fixes + +* [#7442](https://github.com/netbox-community/netbox/issues/7442) - Fix missing actions column on user-configured tables + +--- + ## v3.0.5 (2021-10-04) ### Enhancements diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index c8d0a0e43..d37f24543 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -57,14 +57,14 @@ class BaseTable(tables.Table): if user is not None and not isinstance(user, AnonymousUser): selected_columns = user.config.get(f"tables.{self.__class__.__name__}.columns") if selected_columns: - pk = self.base_columns.pop('pk', None) - actions = self.base_columns.pop('actions', None) + # Show only persistent or selected columns for name, column in self.columns.items(): - if name in selected_columns: + if name in ['pk', 'actions', *selected_columns]: self.columns.show(name) else: self.columns.hide(name) + # Rearrange the sequence to list selected columns first, followed by all remaining columns # TODO: There's probably a more clever way to accomplish this self.sequence = [ @@ -72,12 +72,14 @@ class BaseTable(tables.Table): *[c for c in self.columns.names() if c not in selected_columns] ] - # Always include PK and actions column, if defined on the table - if pk: - self.base_columns['pk'] = pk + # PK column should always come first + if 'pk' in self.sequence: + self.sequence.remove('pk') self.sequence.insert(0, 'pk') - if actions: - self.base_columns['actions'] = actions + + # Actions column should always come last + if 'actions' in self.sequence: + self.sequence.remove('actions') self.sequence.append('actions') # Dynamically update the table's QuerySet to ensure related fields are pre-fetched