oTree Forum >

Remove Table Entry With LiveRecv Based on Data

#1 by PatrickT

Hello, I am creating a gift exchange game where the firms bid on wages. I have a table of bids and bid numbers and would like to remove the row which contains the player's old bid by using their old bid number after a player submits a new bid. Code:

<table id="bid_history" class="table">
<tr>
  <th>Bid Number</th>
  <th>Wage</th>
</tr>
</table>


let bid_history = document.getElementById('bid_history');

(I then have liveRecv function which executes the following line to add elements when a new wage bid is recieved:)
function liveRecv(data){
...
bid_history.innerHTML += "<tr><td>" + data.bid_number + '</td><td>' + data.wage + '</td></tr>';
...
}
I have a variable named previous_bid_number in the data sent to the LiveRecv function which I would like to then use to remove the appropriate row. Any ideas on how to do this would be much appreciated. Thank you!

#2 by Valery

Hi Patrick,
I do not know HTML well enough to give you a reliable answer but given no one replied for a few days I can offer you my guess :)
When you are creating the table, I am guessing, you can create a unique element id for each row. Then you may be able to change the row visibility to hide it.

Regards,
Valery

#3 by BonnEconLab (edited )

Yes, Valery’s suggestion will work. Setting the `visibility` property to `hidden` will, however, leave the space occupied by the respective table row visible. If you want to completely remove the row, you need to set the `display` property to `none`.

More specifically, the following should work (not tested; be sure not to mix up the single and double quotes!):

document.getElementById("bid_history").innerHTML += "<tr id='tr_" + data.bid_number + "'><td>" + data.bid_number + "</td><td>" + data.wage + "</td></tr>";

To make the row invisible, execute

document.getElementById("tr_" + data.previous_bid_number).style.display = "none";

You can also remove it completely:

document.getElementById("tr_" + data.previous_bid_number).remove();

#4 by PatrickT

Hi Valery and BonnEconLab,

Thank you very much for the assistance! I was actually attempting to do something akin to what BonnEconLab suggested before I asked for help, but could not get the id I was setting to work. Thank you for making it clear what I need to do :).

Best,
PatrickT

Write a reply

Set forum username