Refactor worklog handling and table rendering in templates for improved clarity and performance
This commit is contained in:
parent
25e67cce28
commit
bdd2a43c8b
6 changed files with 40 additions and 58 deletions
|
@ -1,8 +1,7 @@
|
|||
{% macro render_table(headers, rows, entry_route=None, title=None) %}
|
||||
{% macro render_table(headers, rows, id, entry_route=None, title=None, per_page=15) %}
|
||||
{% if rows %}
|
||||
<div class="table-responsive">
|
||||
<table
|
||||
id="datatable-{{ title|default('table')|replace(' ', '-')|lower }}"
|
||||
<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 %}">
|
||||
{% if title %}
|
||||
<caption>{{ title }}</caption>
|
||||
|
@ -34,13 +33,29 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
{# console.log($('table[id="datatable-{{ id|default('table')|replace(' ', '-')|lower }}"]'))
|
||||
$('table[id="datatable-{{ id|default('table')|replace(' ', '-')|lower }}"]').DataTable({
|
||||
pageLength: {{ per_page }},
|
||||
lengthChange: false,
|
||||
ordering: true,
|
||||
stateSave: true
|
||||
}) #}
|
||||
new DataTable('#datatable-{{ id|default('table')|replace(' ', '-')|lower }}', {
|
||||
pageLength: {{ per_page }},
|
||||
colReorder: true
|
||||
})
|
||||
})
|
||||
</script>
|
||||
{% else %}
|
||||
<div class="container text-center">No data.</div>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro render_pagination(endpoint, page, has_prev, has_next, total_pages, page_variable='page', extra_args={}) %}
|
||||
{% set prev_args = extra_args.copy() %}
|
||||
{# % set prev_args = extra_args.copy() %}
|
||||
{% set next_args = extra_args.copy() %}
|
||||
{% set first_args = extra_args.copy() %}
|
||||
{% set last_args = extra_args.copy() %}
|
||||
|
@ -78,5 +93,5 @@
|
|||
class="btn btn-primary{% if not has_next %} disabled{% endif %}">Last »</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif % #}
|
||||
{% endmacro %}
|
Loading…
Add table
Add a link
Reference in a new issue