Skip to content

Commit

Permalink
Merge pull request #350 from fsalum/render-table-tbody-class
Browse files Browse the repository at this point in the history
Adding body_classes parameter to render_table
  • Loading branch information
greyli authored Jan 7, 2024
2 parents e048e1a + fde6602 commit ce852e4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
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

0 comments on commit ce852e4

Please sign in to comment.