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

Adding body_classes parameter to render_table #350

Merged
merged 1 commit into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/macros.rst
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ API
caption=None,\
table_classes=None,\
header_classes=None,\
body_classes=None,\
responsive=False,\
responsive_class='table-responsive',\
safe_columns=None,\
Expand All @@ -512,6 +513,7 @@ API
:param caption: A caption to attach to the table.
:param table_classes: A string of classes to apply to the table (e.g ``'table-small table-dark'``).
:param header_classes: A string of classes to apply to the table header (e.g ``'thead-dark'``).
:param body_classes: A string of classes to apply to the table body (e.g ``'table-group-divider'``).
:param responsive: Whether to enable/disable table responsiveness.
:param responsive_class: The responsive class to apply to the table. Default is ``'table-responsive'``.
:param safe_columns: Tuple with columns names to render HTML safe using ``|safe``.
Expand Down
4 changes: 2 additions & 2 deletions examples/bootstrap5/templates/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ <h2>Simple Table</h2>
{{ render_table(messages) }}

<h2>Customized Table</h2>
<pre>{% raw %}{{ render_table(messages, titles, table_classes='table-striped', header_classes='thead-dark', caption='Messages') }}{% endraw %}</pre>
{{ render_table(messages, titles, table_classes='table-striped', header_classes='thead-dark', caption='Messages') }}
<pre>{% raw %}{{ render_table(messages, titles, table_classes='table-striped', header_classes='thead-dark', body_classes='table-group-divider', caption='Messages') }}{% endraw %}</pre>
{{ render_table(messages, titles, table_classes='table-striped', header_classes='thead-dark', body_classes='table-group-divider', caption='Messages') }}

<h2>Responsive Table</h2>
<pre>{% raw %}{{ render_table(messages, responsive=True, responsive_class='table-responsive-sm') }}{% endraw %}</pre>
Expand Down
3 changes: 2 additions & 1 deletion flask_bootstrap/templates/base/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
caption=None,
table_classes=None,
header_classes=None,
body_classes=None,
responsive=False,
responsive_class='table-responsive',
safe_columns=None,
Expand Down Expand Up @@ -75,7 +76,7 @@
{% endif %}
</tr>
</thead>
<tbody>
<tbody{% if body_classes %} class="{{ body_classes }}"{% endif %}>
{% for row in data %}
<tr>
{% for title in titles %}
Expand Down
4 changes: 3 additions & 1 deletion tests/test_bootstrap4/test_render_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ def test():
return render_template_string('''
{% from 'bootstrap4/table.html' import render_table %}
{{ render_table(messages, titles, table_classes='table-striped',
header_classes='thead-dark', caption='Messages') }}
header_classes='thead-dark', body_classes='table-group-divider',
caption='Messages') }}
''', titles=titles, messages=messages)

response = client.get('/table')
data = response.get_data(as_text=True)
assert '<table class="table table-striped">' in data
assert '<thead class="thead-dark">' in data
assert '<tbody class="table-group-divider">' in data
assert '<caption>Messages</caption>' in data


Expand Down
Loading