I have a table in my html file.
<table class="dataframe">
<thead>
<tr style="text-align: right;">
<th>timestamp</th>
<th>cid1</th>
<th>cid2</th>
<th>cid3</th>
<th>cid4</th>
<th>cid5</th>
<th>cid6</th>
<th>cid7</th>
<th>cid8</th>
<th>cid9</th>
</tr>
</thead>
<tbody>
<tr>
<td>2023-04-08 15:39:21</td>
<td>125</td>
<td>4342&</td>
<td>73645</td>
<td>246</td>
<td>4624</td>
<td>1137504</td>
<td>62467</td>
<td>16596</td>
<td>302207.827877119</td>
</tr>
<tr>
<td>2023-04-08 15:39:21</td>
<td>62462</td>
<td>462436</td>
<td>462436</td>
<td>2462436</td>
<td>2</td>
<td>4924872</td>
<td>46246</td>
<td>16619</td>
<td>1769805.989015266</td>
</tr>
</tbody>
</table>
This file created by my python script and I want to add inside js script for recount table without call my backend. Inside data follow the formulas: cid6 = cid4*cid5
and cid9=cid6/cid7*cid8
I want to paste in my html input form for new_cid4
value which must to replace each cid4
values in the table only for rows where ‘cid4’ < ‘new_cid4’. As result I want to recount values of columns cid6, cid9
. Аnd very good if rows where cid4
> new_cid4
will be hided.
I’m pythonist and can’t to make this js script myself. May be JS masters can help me?
3
Answers
Basically, you need to add an event listener to the element in question.
First, query elements from the document using
document.querySelector()
(assuming you have one<input>
and one<button>
; I made a snippet below for your reference):Then, add an event listener:
Try it:
Version with html input. It recalculate values and hides rows where this condition is not met
cid4 <= new_cid4
. It also gets all the table values and create the array of objects out of them.First, you need to determine
th
cell indices, and then make a calculationtbody tr
based on them.