Ensure selection column is always placed last in the column order for improved table layout

This commit is contained in:
Ross
2025-11-01 20:57:35 +00:00
parent a269cf1f52
commit cbf4c3497d
+22
View File
@@ -35,6 +35,28 @@ class SelectionTable(tables.Table):
# locate tables that support row selection.
attrs = {"class": "table js-row-selectable", "data-selection-name": "selection"}
def __init__(self, *args, **kwargs):
# Ensure selection column is always placed last in the column order
# so that table actions/controls appear to the right. We attempt to
# reorder columns after initialization; if django-tables2 provides
# `reorder_columns`, use it, otherwise fall back to setting
# `self.sequence`.
super().__init__(*args, **kwargs)
try:
cols = list(self.columns.names())
if 'selection' in cols:
cols.remove('selection')
cols.append('selection')
try:
# Preferred API when available
self.reorder_columns(cols)
except Exception:
# Fallback: set sequence attribute
self.sequence = tuple(cols)
except Exception:
# Defensive: don't break table rendering if introspection fails
pass
class SingleImageColumn(tables.Column):
def render(self, value):
try: