I recently created a function that does some complicated name matching based on user input into a website and returns the result as an html file in a table format. My question is how do I add click feature on each row?
df = get_cust_info() # returns a pandas dataframe
df.to_html('results.html') #converts the dataframe to html
Idea is user types his name, (if he misspells it, the program suggests following names. Hence a table is returned in html format.
Now I want to add click feature on each row. The click hopefully requeries the database that I have internally and returns the right information. It has to be dynamic. By this, I mean if one row is returned, you can click on only one row. if 10 rows are returned, you should be able to click on any row. Thank you
Edit: Based on the answer below, I added the following lines but am still having trouble getting the row to click. Not sure what im doing wrong.
A sample html file
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;"><th></th>
<th>CustomerName</th>
<th>firstName</th>
<th>MiddleName</th>
<th>LastName</th>
<th>Address</th>
<th>zip</th>
<th>State</th>
<th>score_first</th>
<th>score_second</th>
<th>score_third</th>
</tr>
</thead>
<tbody>
<tr>
<th>5046</th>
<td>JAMES G STAHL</td>
<td>JAMES</td>
<td>G</td>
<td>STAHL</td>
<td>4090 BECK RD</td>
<td>44256</td>
<td>OH</td>
<td>0.97</td>
<td>1.0</td>
<td>0.91</td>
<tr>
<th>5050</th>
<td>JONATHAN STAHL</td>
<td>JONATHAN</td>
<td>None</td>
<td>STAHL</td>
<td>4114 BECK RD</td>
<td>44256</td>
<td>OH</td>
<td>0.57</td>
<td>NaN</td>
<td>0.91</td>
</tr>
</tbody>
</table>
Edit 2: Upon further search on another stackoverflow question, I tried adding this to the bottom.
<script>
document.querySelector(".dataframe").addEventListener("click", function(e) {
var row = e.target;
while (row.matches && !row.matches("tr")) {
row = row.parentNode;
}
if (row.matches && row.matches("tr") {
alert(row.innerHTML);
}
});
</script>
Still not working. Im sorry im new to javascript/jquery. If anyone can help that would be a huge help