I'm using python Flask render_template to return a html page for a route of my python app, and in the html I want to use the bootstrap-table-filter-control as described in the bootstrap example here. However the example given seem to be using a table from a local json file. Here's the code given in the example:
<link href="https://unpkg.com/bootstrap-table@1.16.0/dist/bootstrap-table.min.css" rel="stylesheet">
<script src="https://unpkg.com/bootstrap-table@1.16.0/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/bootstrap-table@1.16.0/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script>
<table
id="table"
data-url="json/data1.json" ## this looks like the code to get the table's data
data-filter-control="true"
data-show-search-clear-button="true">
<thead>
<tr>
<th data-field="id">ID</th>
<th data-field="name" data-filter-control="input">Item Name</th>
<th data-field="price" data-filter-control="select">Item Price</th>
</tr>
</thead>
</table>
<script>
$(function() {
$('#table').bootstrapTable()
})
</script>
How do I replace the
data-url="json/data1.json"
with my own table from my python dataframe passed from the main.py app? I tried the below for my html but it doesn't work:
{% for table in tables %} <table id="table" data = {{ table|safe }} data-filter-control="true" data-show-search-clear-button="true" class="table-striped"> <thead> <tr> <th data-field="columnA" data-filter-control="input">column A</th> <th data-field="columnB" data-filter-control="select">columnB</th> <th data-field="columnC" data-filter-control="select">columnC</th> </tr> </thead> <tbody> <!-- I have tried to put {{ table|safe }} here but doesn't work --> </tbody> </table> {% endfor %}
My python route looks like this:
@app.route('/')
def hello():
return render_template('yield.html', tables=[df3.to_html(classes='data', header="true")])
where df3 is the dataframe I want to display as a table in the yield.html with bootstrap filter controls.