table_htmx.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. {% load django_tables2 %}
  2. <table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %}>
  3. {% if table.show_header %}
  4. <thead>
  5. <tr>
  6. {% for column in table.columns %}
  7. {% if column.orderable %}
  8. <th {{ column.attrs.th.as_html }}>
  9. <a href="#"
  10. hx-get="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}"
  11. hx-target="#object_list"
  12. hx-push-url="true"
  13. >{{ column.header }}</a>
  14. </th>
  15. {% else %}
  16. <th {{ column.attrs.th.as_html }}>{{ column.header }}</th>
  17. {% endif %}
  18. {% endfor %}
  19. </tr>
  20. </thead>
  21. {% endif %}
  22. <tbody>
  23. {% for row in table.page.object_list|default:table.rows %}
  24. <tr {{ row.attrs.as_html }}>
  25. {% for column, cell in row.items %}
  26. <td {{ column.attrs.td.as_html }}>{{ cell }}</td>
  27. {% endfor %}
  28. </tr>
  29. {% empty %}
  30. {% if table.empty_text %}
  31. <tr>
  32. <td colspan="{{ table.columns|length }}" class="text-center text-muted">&mdash; {{ table.empty_text }} &mdash;</td>
  33. </tr>
  34. {% endif %}
  35. {% endfor %}
  36. </tbody>
  37. {% if table.has_footer %}
  38. <tfoot>
  39. <tr>
  40. {% for column in table.columns %}
  41. <td>{{ column.footer }}</td>
  42. {% endfor %}
  43. </tr>
  44. </tfoot>
  45. {% endif %}
  46. </table>