I am still in the process of learning how everything works, but I am trying to put together a project that has a table that needs to be sorted. I am using flask to generate the pages, and plan to keep the information for the table stored in sql. For the time being, I am using a hard-coded table of dictionaries that will eventually be converted from this sql database. I have successfully gotten my html page to load the flask table element into a table on the webpage. However, I would like to allow users to be able to sort through this table, and I believe using Javascript would be the best way to do this.
However, before I begin to write the sorting function, the problem I am having is somehow passing the table of dictionaries that is rendered in Flask into my Javascript file. I believe it would be best to have the html render the table from Flask first, and then have Javascript retrieve the table information straight from the html page.
To be clear, the format of the table in Flask is like this:
items = [{'item 1': "Name", 'item 2': "Name"}, {'item 1': "Name2", 'item 2': "Name2"}]
and is rendered in the html page like this:
{% for row in items %}
<tr>
<td class="item1">{{ row.item1 }}</td>
<td class="item2">{{ row.item2 }}</td>
</tr>
{% endfor %}
And somehow, I would like to render the same "items" variable in Javascript using the html page as its source. I have been able to find tutorials explaining a sorting function in Javascript however, these tutorials assume that the table already exists in JS, and I am unsure how to render it dynamically like this. Does anyone know how I would go about doing this? Thanks.