diff --git a/generic/tables.py b/generic/tables.py index d1f29a64..77b38d60 100644 --- a/generic/tables.py +++ b/generic/tables.py @@ -58,6 +58,14 @@ class SelectionTable(tables.Table): # Defensive: don't break table rendering if introspection fails pass + # By default render the row selection controls above the table so + # templates don't need to include `{{ table.row_selection_controls }}`. + try: + # `row_selection_controls` is already marked safe HTML. + self.caption = self.row_selection_controls + except Exception: + pass + @property def row_selection_controls(self): """Return HTML for the row-selection control bar. diff --git a/templates/base.html b/templates/base.html index a60421b3..c0993e34 100644 --- a/templates/base.html +++ b/templates/base.html @@ -351,44 +351,8 @@ return token ? idBase + '-' + token : idBase; } - // Ensure every selectable table has a row-selection control block. If the - // page author didn't render the controls, create them automatically and - // insert them before the table so the behavior is available out-of-the-box. - function ensureControlsForTable(table) { - if (!table) return; - // detect an existing nearby toggle button - var existing = table.previousElementSibling && table.previousElementSibling.querySelector && table.previousElementSibling.querySelector('[id^="toggle-row-selection"]'); - if (existing) return; // already present - - // generate a short token for unique IDs - var token = (Date.now().toString(16) + Math.floor(Math.random()*0xffff).toString(16)); - - var wrapper = document.createElement('div'); - wrapper.className = 'row-selection-controls-wrapper'; - wrapper.innerHTML = '