Ensure selection column is always placed last in the column order for improved table layout
This commit is contained in:
@@ -35,6 +35,28 @@ class SelectionTable(tables.Table):
|
|||||||
# locate tables that support row selection.
|
# locate tables that support row selection.
|
||||||
attrs = {"class": "table js-row-selectable", "data-selection-name": "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):
|
class SingleImageColumn(tables.Column):
|
||||||
def render(self, value):
|
def render(self, value):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user