I got an HTML Table with a Button on the left side.
What I would like to achieve is that by using the Button the Table splits below that row and another table with different columns and rows appears with the full width of the original table.. basically the new table pushes the rest of the original table down the page.
What would be a solid approach to this without using any big libraries/frameworks?
<table>
<tr>
<th></th>
<th>Lieferant</th>
<th>urspüngliches Lieferdatum</th>
<th>Liefer-ID</th>
</tr>
<tr class="new_tr verspaetet">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Müller GmbH</td>
<td>20.10.2022</td>
<td>12384123</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Wasser GmbH</td>
<td>heute</td>
<td>12385533</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Grill GmbH</td>
<td>heute</td>
<td>94728544</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Bier GmbH</td>
<td>heute</td>
<td>82375440</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Pflaumen GmbH</td>
<td>heute</td>
<td>52469874</td>
</tr>
<tr class="new_tr">
<td><input type="image" src="./img/down-arrow.png" /></td>
<td>Bananen GmbH</td>
<td>heute</td>
<td>16543897</td>
</tr>
</tr>
“`
2
Answers
Tables are not worth the hassle, learning
display: grid
will save you pain and timeFirst, generate the inner table in a separate row of the table you have, and initially hide it. Something like:
The empty
td
serves to get a bit of indentation of the inner table. Thecolspan
attribute ensures that the table occupies the remaining column space of the outer table.Once you have those inner tables embedded in your HTML, you can add some JavaScript to respond to a click on the arrow cell. Give that arrow cell a specific class so a click on it can be easily recognised.
Here is how that looks: