Fixes #16101: Fix initial loading of pagination widget for dynamic object tables

This commit is contained in:
Jeremy Stretch 2024-05-13 16:00:07 -04:00
parent e0f138dea2
commit c7850b586b
4 changed files with 15 additions and 12 deletions

View File

@ -2,15 +2,17 @@
{% load helpers %} {% load helpers %}
{% load render_table from django_tables2 %} {% load render_table from django_tables2 %}
{% with preferences|get_key:"pagination.placement" as paginator_placement %} <div class="htmx-container table-responsive">
{% if paginator_placement == 'top' or paginator_placement == 'both' %} {% with preferences|get_key:"pagination.placement" as paginator_placement %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page placement='top' %} {% if paginator_placement == 'top' or paginator_placement == 'both' %}
{% endif %} {% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page placement='top' %}
{% render_table table 'inc/table_htmx.html' %} {% endif %}
{% if paginator_placement != 'top' %} {% render_table table 'inc/table_htmx.html' %}
{% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page %} {% if paginator_placement != 'top' %}
{% endif %} {% include 'inc/paginator.html' with htmx=True table=table paginator=table.paginator page=table.page %}
{% endwith %} {% endif %}
{% endwith %}
</div>
{# Include the updated object count for display elsewhere on the page #} {# 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> <div class="d-none" hx-swap-oob="innerHTML:.total-object-count">{{ table.rows|length }}</div>

View File

@ -5,7 +5,8 @@
<div <div
class="d-flex justify-content-between align-items-center border-{% if placement == 'top' %}bottom{% else %}top{% endif %} p-2" 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-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 %} {% if not table.embedded %}hx-push-url="true"{% endif %}
> >

View File

@ -1,5 +1,5 @@
{% load django_tables2 %} {% 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 %} {% if table.show_header %}
<thead <thead
hx-target="closest .htmx-container" hx-target="closest .htmx-container"

View File

@ -1,5 +1,5 @@
<div class="htmx-container table-responsive" <div class="htmx-container table-responsive"
hx-get="{% url viewname %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" hx-get="{% url viewname %}{% if url_params %}?{{ url_params.urlencode }}{% endif %}"
hx-target="this" hx-target="this"
hx-trigger="load" hx-select="table" hx-swap="innerHTML" hx-trigger="load" hx-select=".htmx-container" hx-swap="outerHTML"
></div> ></div>