table_htmx.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. {% load django_tables2 %}
  2. <table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %} hx-disinherit="hx-target hx-select hx-swap">
  3. {% if table.show_header %}
  4. <thead
  5. hx-target="closest .htmx-container"
  6. {% if not table.embedded %} hx-push-url="true"{% endif %}
  7. >
  8. <tr>
  9. {% for column in table.columns %}
  10. {% if column.orderable %}
  11. <th {{ column.attrs.th.as_html }}>
  12. {% if column.is_ordered %}
  13. <div class="float-end">
  14. <a href="#"
  15. hx-get="{{ table.htmx_url }}{% querystring table.prefixed_order_by_field='' %}"
  16. class="text-danger"
  17. ><i class="mdi mdi-close"></i></a>
  18. </div>
  19. {% endif %}
  20. <a href="#"
  21. hx-get="{{ table.htmx_url }}{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}"
  22. >{{ column.header }}</a>
  23. </th>
  24. {% else %}
  25. <th {{ column.attrs.th.as_html }}>{{ column.header }}</th>
  26. {% endif %}
  27. {% endfor %}
  28. </tr>
  29. </thead>
  30. {% endif %}
  31. <tbody>
  32. {% for row in table.page.object_list|default:table.rows %}
  33. <tr {{ row.attrs.as_html }}>
  34. {% for column, cell in row.items %}
  35. <td {{ column.attrs.td.as_html }}>{{ cell }}</td>
  36. {% endfor %}
  37. </tr>
  38. {% empty %}
  39. {% if table.empty_text %}
  40. <tr>
  41. <td colspan="{{ table.columns|length }}" class="text-center text-muted">&mdash; {{ table.empty_text }} &mdash;</td>
  42. </tr>
  43. {% endif %}
  44. {% endfor %}
  45. </tbody>
  46. {% if table.has_footer %}
  47. <tfoot>
  48. <tr>
  49. {% for column in table.columns %}
  50. <td>{{ column.footer }}</td>
  51. {% endfor %}
  52. </tr>
  53. </tfoot>
  54. {% endif %}
  55. </table>