---
title: "Cornelius (@cornelius23) | Hashnode"
description: "Cornelius (@cornelius23) writes on Hashnode. Read their latest articles and follow their work."
url: "https://hashnode.com/@cornelius23"
---

@cornelius23

# Cornelius

@cornelius23 · Joined July 2022

## Comments

[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](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7/comment/62d953fde3738c59b0b78113)

Comment · Article · Jul 21, 2022 · [Responsive table with Django and htmx](https://hashnode.com/posts/responsive-table-with-django-and-htmx/6232d50efaf37c0675928ef7)
