Skip to content

Commit

Permalink
Fixes #16101: Fix initial loading of pagination widget for dynamic ob…
Browse files Browse the repository at this point in the history
…ject tables
  • Loading branch information
jeremystretch committed May 13, 2024
1 parent e0f138d commit ddf0c57
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
20 changes: 11 additions & 9 deletions netbox/templates/htmx/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
{% load helpers %}
{% load render_table from django_tables2 %}

{% with preferences|get_key:"pagination.placement" as paginator_placement %}
{% if paginator_placement == 'top' or paginator_placement == 'both' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page placement='top' %}
{% endif %}
{% render_table table 'inc/table_htmx.html' %}
{% if paginator_placement != 'top' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page %}
{% endif %}
{% endwith %}
<div class="htmx-container table-responsive">
{% with preferences|get_key:"pagination.placement" as paginator_placement %}
{% if paginator_placement == 'top' or paginator_placement == 'both' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page placement='top' %}
{% endif %}
{% render_table table 'inc/table_htmx.html' %}
{% if paginator_placement != 'top' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page %}
{% endif %}
{% endwith %}
</div>

{# Include the updated object count for display elsewhere on the page #}
<div class="d-none" hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div>
3 changes: 2 additions & 1 deletion netbox/templates/inc/paginator.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<div
class="d-flex justify-content-between align-items-center border-{% if placement == 'top' %}bottom{% else %}top{% endif %} p-2"
hx-target="closest .htmx-container"
hx-disinherit="hx-select hx-swap"
hx-disinherit="hx-select"
hx-swap="outerHTML"
{% if not table.embedded %}hx-push-url="true"{% endif %}
>

Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/inc/table_htmx.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load django_tables2 %}
<table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %} hx-disinherit="hx-target hx-select hx-swap">
<table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %} hx-disinherit="hx-target hx-select" hx-swap="outerHTML">
{% if table.show_header %}
<thead
hx-target="closest .htmx-container"
Expand Down
2 changes: 1 addition & 1 deletion netbox/utilities/templates/builtins/htmx_table.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="htmx-container table-responsive"
hx-get="{% url viewname %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}"
hx-target="this"
hx-trigger="load" hx-select="table" hx-swap="innerHTML"
hx-trigger="load" hx-select=".htmx-container" hx-swap="outerHTML"
></div>

0 comments on commit ddf0c57

Please sign in to comment.