Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional parameter for render_table() #287

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 42 additions & 26 deletions flask_bootstrap/templates/base/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
model=None,
show_actions=False,
actions_title='Actions',
actions_first=False,
custom_actions=None,
view_url=None,
edit_url=None,
Expand All @@ -57,9 +58,11 @@
{% endif %}
<thead{% if header_classes %} class="{{ header_classes }}"{% endif %}>
<tr>
{% for title in titles %}
<th scope="col">{{ title[1] }}</th>
{% endfor %}
{% if not actions_first %}
{% for title in titles %}
<th scope="col">{{ title[1] }}</th>
{% endfor %}
{% endif %}
{% if show_actions %}
<th scope="col">{{ actions_title }}
{% if new_url %}
Expand All @@ -75,38 +78,48 @@
{% endif %}
</th>
{% endif %}
{% if actions_first %}
{% for title in titles %}
<th scope="col">{{ title[1] }}</th>
{% endfor %}
{% endif %}
</tr>
</thead>
<tbody>
{% for row in data %}
<tr>
{% for title in titles %}
{% set key = title[0] %}
{% set value = row[key] %}
{%- if key == primary_key -%}
<th scope="row">
{%- else -%}
<td>
{%- endif -%}
{%- if value is string -%}
{%- if safe_columns and key in safe_columns -%}
{{ value|safe }}
{% set show_main_cols %}
{% for title in titles %}
{% set key = title[0] %}
{% set value = row[key] %}
{%- if key == primary_key -%}
<th scope="row">
{%- else -%}
{%- if urlize_columns and key in urlize_columns -%}
{{ value|urlize }}
<td>
{%- endif -%}
{%- if value is string -%}
{%- if safe_columns and key in safe_columns -%}
{{ value|safe }}
{%- else -%}
{{ value }}
{%- if urlize_columns and key in urlize_columns -%}
{{ value|urlize }}
{%- else -%}
{{ value }}
{%- endif -%}
{%- endif -%}
{%- else -%}
{{ value }}
{%- endif -%}
{%- else -%}
{{ value }}
{%- endif -%}
{%- if key == primary_key -%}
</th>
{%- else -%}
</td>
{%- endif -%}
{% endfor %}
{%- if key == primary_key -%}
</th>
{%- else -%}
</td>
{%- endif -%}
{% endfor %}
{% endset %}
{% if not actions_first %}
{{show_main_cols}}
{% endif %}
{% if show_actions %}
<td>
{% if custom_actions %}
Expand Down Expand Up @@ -161,6 +174,9 @@
{% endif %}
</td>
{% endif %}
{% if actions_first %}
{{show_main_cols}}
{% endif %}
</tr>
{% endfor %}
</tbody>
Expand Down