---
title: "Discussion on \"Responsive table with Django and htmx\" | Hashnode"
description: "Discussion on \"Responsive table with Django and htmx\". As a developer, you will need to create tables in your web applications. To create a table in Django, you typically implement a set of APIs on the server-side that transfer data to the client and use a Javascript table library on the client-side. But..."
url: "https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Responsive table with Django and htmx](https://enzircle.com/responsive-table-with-django-and-htmx?utm_source=hashnode&utm_medium=feed)

As a developer, you will need to create tables in your web applications. To create a table in Django, you typically implement a set of APIs on the server-side that transfer data to the client and use a Javascript table library on the client-side. But...

Mar 17, 2022 · 8 min read · enzircle.com  
Updated Aug 18, 2022  
Read the article

-   [#django](https://hashnode.com/tag/django)
-   [#python3](https://hashnode.com/tag/python3)
-   [#python](https://hashnode.com/tag/python)

## Written by

[Joash Xu](https://hashnode.com/@joashxu)

@joashxu · Jakarta, Indonesia

  
[View profile](https://hashnode.com/@joashxu)

## Responses 5

Markdown supported · ⌘↵ to post

[Walt Winnert](https://hashnode.com/@wwinnert)

[Jan 18, 2024](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/65a92d762b8b36ab12bad5ef)

Great article, thanks for that, really helpful! One thing to mention: Won't the search reset the ordering of the columns? Do you have any elegant ideas on how to solve this? I tried adding hx-push-url="true" to the column ordering htmx which kind of works but doesn't seem perfect to me.

[Marcel Wijngaard](https://hashnode.com/@marcovino)

[Dec 11, 2022](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/6396103115750808b269d6fe)

Thanks for this very helpful explanation.

[Kylewoo](https://hashnode.com/@Kylewoo2022)

[Aug 27, 2022](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/630a28c138843b7139786061)

Hello [Joash Xu](https://hashnode.com/@joashxu) Your article is awosome. Is it possible to share detailed contents regarding base.html, views.py etc.

I'm trying to make the similier table, but, It's not working to see table at the moment.

I appreciate if you share whole files if possible.

[Joash Xu](https://hashnode.com/@joashxu)

[Sep 1, 2022](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/630a28c138843b7139786061#reply-63103c0356df9e8e5025aec7)

You can look at the structure and code at the following GitHub repo: github.com/joashxu/dj-htmx-fun.

Hope it helps.

[kijoupa](https://hashnode.com/@kijoupa)

[Oct 1, 2022](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/630a28c138843b7139786061#reply-6338171de594fa4ba3b8fcb3)

You code is wonderful. Thanks for sharing :) [Joash Xu](https://hashnode.com/@joashxu)

[Cornelius](https://hashnode.com/@cornelius23)

[Jul 21, 2022](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/62d953fde3738c59b0b78113)

Awesome post, thank you! A perfect integration of htmx, django-filter and django-tables.

With some minor changes also infinite scroll is possible:

Add a template rendering the table rows with the last row triggering the loading of more rows (google htmx infinite-scroll. I cant post links here???) . Add url parameter lazy=1 in hx-get to flag infinite scroll request:

```
{# templates/bootstrap_htmx_rows.html #}
{% load django_tables2 %}
{% load i18n %}
{% for row in table.paginated_rows %}
    {% with lastrow=forloop.last %}
      {% block table.tbody.row %}
      <tr {{ row.attrs.as_html }} {% if lastrow and table.page.has_next %}hx-get="{% querystring table.prefixed_page_field=table.page.next_page_number "lazy"="1" %}" hx-trigger="revealed" hx-swap="afterend"{% endif %}>
          {% for column, cell in row.items %}
              <td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
          {% endfor %}
      </tr>
      {% endblock table.tbody.row %}
    {% endwith %}
{% empty %}
    {% if table.empty_text %}
    {% block table.tbody.empty_text %}
        <tr><td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td></tr>
    {% endblock table.tbody.empty_text %}
    {% endif %}
{% endfor %}
```

Override the table.tbody block in bootstrap\_htmx.html and make use of the row rednering template (plus clear pagination blocks):

```
{% block table.tbody %}
    <tbody {{ table.attrs.tbody.as_html }}>
      {% include 'bootstrap_tables_htmx_rows.html' %}
    </tbody>
{% endblock table.tbody %}

{% block pagination.previous %}
{% endblock pagination.previous %}

{% block pagination.range %}
{% endblock pagination.range %}

{% block pagination.next %}
{% endblock pagination.next %}
```

In view check if htmx request is due to infinite scroll (lazy in request.GET) then only render rows. If htmx request is due to filter/sort update the render full table.

```
    def get_template_names(self):
        if self.request.htmx:
            if "lazy" in self.request.GET:
                # Render only rows
                template_name = "bootstrap_tables_htmx_rows.html"
            else:
                # Render Full table
                template_name = "product_table_partial.html"
        else:
            # Render full page
            template_name = "product_table_htmx.html"

        return template_name
```

[Meera Khanna](https://hashnode.com/@MeeraKhanna)

[Jul 5, 2022](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/62c3e8adccecfb25bbc7acbf)

Dear Joash Xu, Thank you! But, may I request you 2 things? folder structure of this project & syntax used to call the stylesheet inside html files? Also, 'product\_htmx' inside ""- hx-get="{% url 'product\_htmx' %}" "", is it right term?

I am completely new to application development and trying to develop data entry web app using django. I tried to make your solution run without any error, but the page is appearing blank rendering nothing. So need help.

[Joash Xu](https://hashnode.com/@joashxu)

[Jul 7, 2022](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/62c3e8adccecfb25bbc7acbf#reply-62c63241c8efe473b8fe522c)

Hi Meera,

You can look at the structure and code at the following GitHub repo: [github.com/joashxu/dj-htmx-fun.](https://github.com/joashxu/dj-htmx-fun.)

Hope it helps.

[Meera Khanna](https://hashnode.com/@MeeraKhanna)

[Jul 12, 2022](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/62c3e8adccecfb25bbc7acbf#reply-62cd10380ba13ab923f69f61)

[Joash Xu](https://hashnode.com/@joashxu) Yes Joash Xu. Thank you very much! Able to reproduce now and getting the page working :)
