Implement row selection controls in templates and refactor related JavaScript functionality
This commit is contained in:
@@ -57,6 +57,36 @@ class SelectionTable(tables.Table):
|
||||
# Defensive: don't break table rendering if introspection fails
|
||||
pass
|
||||
|
||||
@property
|
||||
def row_selection_controls(self):
|
||||
"""Return HTML for the row-selection control bar.
|
||||
|
||||
Usage: render in template with `{{ table.row_selection_controls|safe }}`
|
||||
|
||||
The control IDs are suffixed with a small per-instance token to
|
||||
avoid collisions when multiple tables are present on the same page.
|
||||
"""
|
||||
token = format(id(self), 'x')
|
||||
|
||||
html = (
|
||||
"<div class=\"d-flex justify-content-between align-items-center mb-2\">"
|
||||
" <div>"
|
||||
" <button class=\"btn btn-outline-secondary btn-sm\" id=\"toggle-row-selection-{}\" type=\"button\">Enable row selection</button>"
|
||||
" <div id=\"selection-controls-{}\" class=\"btn-group ms-2\" role=\"group\" style=\"display:none;\">"
|
||||
" <button class=\"btn btn-sm btn-outline-primary\" id=\"select-all-{}\">Select all</button>"
|
||||
" <button class=\"btn btn-sm btn-outline-secondary\" id=\"clear-selection-{}\">Clear</button>"
|
||||
" </div>"
|
||||
" </div>"
|
||||
" <div>"
|
||||
" <small class=\"text-muted\">Selected: <span id=\"selected-count-{}\">0</span></small>"
|
||||
" </div>"
|
||||
"</div>"
|
||||
).format(token, token, token, token, token)
|
||||
|
||||
# Also include a small data attribute so client scripts can locate the
|
||||
# controls by selection name if they prefer.
|
||||
return format_html(html)
|
||||
|
||||
class SingleImageColumn(tables.Column):
|
||||
def render(self, value):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user