As part of PSET8 finance additional implementations, I want to dynamically colour the table in history.html.
The simple code uses jinja2? to populate and print out a table in html.
{% extends "layout.html" %}
{% block title %}
Log In
{% endblock %}
{% block main %}
<h2>History</h2>
<table>
<tr>
<th>Action</th>
<th>Symbol</th>
<th>Shares</th>
<th>Price per share</th>
<th>Timestamp</th>
</tr>
{% for row in transactions %}
<tr>
<td>{{ row['type'] }}</td>
<td>{{ row['symbol'] }}</td>
<td>{{ row['shares'] }}</td>
<td>{{ row['price'] }}</td>
<td>{{ row['time'] }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}
What I want to do is add some code (JS probably?) that will look at value inside the cell row['type'] and then, depending on that value, change the background of that entire row into a certain colour. However, I have no idea where to begin.
innerText
of the things in the table by iterating over them using a for loop, and then make some code that converts the text into a color and then insert that using abackgroundColor
, and then use asetInterval
to update. Then again, I'm probably not the best person to answer this. Just look at my stackoverflow questions.