Refactor dynamic_table macro: remove rows parameter, simplify tbody handling, and add pagination support
This commit is contained in:
parent
cc7cef6145
commit
ce4164d77c
1 changed files with 6 additions and 22 deletions
|
|
@ -51,7 +51,7 @@
|
|||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro dynamic_table(id, headers=none, rows=none, fields=none, entry_route=None, title=None, per_page=15, offset=0, refresh_url=none) %}
|
||||
{% macro dynamic_table(id, headers=none, fields=none, entry_route=None, title=None, per_page=15, offset=0, refresh_url=none) %}
|
||||
<!-- Table Fragment -->
|
||||
|
||||
{% if rows or refresh_url %}
|
||||
|
|
@ -64,7 +64,7 @@
|
|||
headers: {{ headers|tojson if headers else "[]" }},
|
||||
perPage: {{ per_page }},
|
||||
offset: {{ offset if offset else 0 }},
|
||||
fields: {{ fields|tojson if fields else "[]" }},
|
||||
fields: {{ fields|tojson if fields else "[]" }}
|
||||
})'>
|
||||
<table id="datatable-{{ id|default('table')|replace(' ', '-')|lower }}"
|
||||
class="table table-bordered table-sm table-hover table-striped table-light m-0{% if title %} caption-top{% endif %}">
|
||||
|
|
@ -75,27 +75,11 @@
|
|||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody x-ref="body">
|
||||
{% if rows %}
|
||||
{% for row in rows %}
|
||||
<tr {% if entry_route %}onclick="window.location='{{ url_for('main.' + entry_route, id=row.id) }}'"
|
||||
style="cursor: pointer;"{% endif %}{% if row['highlight'] %} class="table-info"{% endif %}>
|
||||
{% for cell in row.cells %}
|
||||
<td class="text-nowrap{% if cell.type=='bool' %} text-center{% endif %}">
|
||||
{% if cell.type == 'bool' %}
|
||||
{{ cell.html | safe }}
|
||||
{% elif cell.url %}
|
||||
<a class="link-success link-underline-opacity-0" href="{{ cell.url }}">{{ cell.text }}</a>
|
||||
{% else %}
|
||||
{{ cell.text or '-' }}
|
||||
{% endif %}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</tbody>
|
||||
<tbody x-ref="body"></tbody>
|
||||
</table>
|
||||
<nav>
|
||||
<ul class="pagination"></ul>
|
||||
</nav>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="container text-center">No data.</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue