Skip to content

Commit 7bae448

Browse files
16733 fix bulk edit/delete buttons with quick search (#17130)
* 16733 fix bulk edit/delete buttons with quick search * 16733 fix bulk edit/delete buttons with quick search * 16733 fix bulk edit/delete buttons with quick search * Wrap bulk action buttons with .bulk-action-buttons for replacement via HTMX --------- Co-authored-by: Jeremy Stretch <[email protected]>
1 parent 5ebdb7c commit 7bae448

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

netbox/netbox/views/generic/bulk_views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ def get(self, request):
178178
table.columns.hide('pk')
179179
return render(request, 'htmx/table.html', {
180180
'table': table,
181+
'model': model,
182+
'actions': actions,
181183
})
182184

183185
context = {

netbox/templates/generic/object_list.html

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,7 @@
8181
{% if table.paginator.num_pages > 1 %}
8282
<div id="select-all-box" class="d-none card d-print-none">
8383
<div class="form col-md-12">
84-
<div class="card-body">
85-
<div class="float-end">
86-
{% if 'bulk_edit' in actions %}
87-
{% bulk_edit_button model query_params=request.GET %}
88-
{% endif %}
89-
{% if 'bulk_delete' in actions %}
90-
{% bulk_delete_button model query_params=request.GET %}
91-
{% endif %}
92-
</div>
84+
<div class="card-body d-flex justify-content-between">
9385
<div class="form-check">
9486
<input type="checkbox" id="select-all" name="_all" class="form-check-input" />
9587
<label for="select-all" class="form-check-label">
@@ -98,6 +90,14 @@
9890
{% endblocktrans %}
9991
</label>
10092
</div>
93+
<div class="bulk-action-buttons">
94+
{% if 'bulk_edit' in actions %}
95+
{% bulk_edit_button model query_params=request.GET %}
96+
{% endif %}
97+
{% if 'bulk_delete' in actions %}
98+
{% bulk_delete_button model query_params=request.GET %}
99+
{% endif %}
100+
</div>
101101
</div>
102102
</div>
103103
</div>
@@ -123,12 +123,14 @@
123123
{# Form buttons #}
124124
<div class="btn-list d-print-none mt-2">
125125
{% block bulk_buttons %}
126-
{% if 'bulk_edit' in actions %}
127-
{% bulk_edit_button model query_params=request.GET %}
128-
{% endif %}
129-
{% if 'bulk_delete' in actions %}
130-
{% bulk_delete_button model query_params=request.GET %}
131-
{% endif %}
126+
<div class="bulk-action-buttons">
127+
{% if 'bulk_edit' in actions %}
128+
{% bulk_edit_button model query_params=request.GET %}
129+
{% endif %}
130+
{% if 'bulk_delete' in actions %}
131+
{% bulk_delete_button model query_params=request.GET %}
132+
{% endif %}
133+
</div>
132134
{% endblock %}
133135
</div>
134136
{# /Form buttons #}

netbox/templates/htmx/table.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{# Render an HTMX-enabled table with paginator #}
22
{% load helpers %}
3+
{% load buttons %}
34
{% load render_table from django_tables2 %}
45

56
<div class="htmx-container table-responsive">
@@ -14,5 +15,19 @@
1415
{% endwith %}
1516
</div>
1617

17-
{# Include the updated object count for display elsewhere on the page #}
18-
<div class="d-none" hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div>
18+
{% if request.htmx %}
19+
{# Include the updated object count for display elsewhere on the page #}
20+
<div hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div>
21+
22+
{# Update the bulk action buttons with new query parameters #}
23+
{% if actions %}
24+
<div class="bulk-action-buttons" hx-swap-oob="outerHTML:.bulk-action-buttons">
25+
{% if 'bulk_edit' in actions %}
26+
{% bulk_edit_button model query_params=request.GET %}
27+
{% endif %}
28+
{% if 'bulk_delete' in actions %}
29+
{% bulk_delete_button model query_params=request.GET %}
30+
{% endif %}
31+
</div>
32+
{% endif %}
33+
{% endif %}

0 commit comments

Comments
 (0)