Mike 0

I would like to be able to make a table where each row contains a link that would drop down a sub table.

I have implemented this already by creating an entire table for each single row and then another table is displayed under each one. I think this is probably far from the best way to accomplish this.

Any ideas?

Update:

For example, this is somewhat how I have done it now. The code is ugly and I would like a better way.

<style type="text/css">
.table{
border-collapse:collapse;
}
.table td{
border:1px solid black;
}
.sub{
margin-left:25px;
}
</style>

<table class='table'>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
</tr>
</table>
<table class='sub table'>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
</table>
<table class='table'>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
</tr>
</table>
<table class='sub table'>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
</table>
<table class='table'>
<tr>
<td>cell 1</td>
<td>cell 2</td>
<td>cell 3</td>
</tr>
</table>
<table class='sub table'>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
<tr><td>data1</td><td>data2</td><td>data3</td></tr>
</table>
  • http://tinypic.com/view.php?pic=fejnli&s=7 Mike over 8 years ago

2 answers

Sisira 95
0
points

You can Use this structure [DL, DT, DD] for tabular data and apply css accordingly to represent as tabular.

Column1
Column2
Column3
Column4
data1
data2
data3
data4

If there are further list items [UL, LI] under each link then use

tag.

Hope i understood.

Answered over 8 years ago by Sisira
  • I am not sure what you mean. Also I may not have worded my question properly, I will update it. Mike over 8 years ago
  • Don't use a definition list '<dl>' if you need to display tabular data - use a table! The one time when it's ok to use a table and people suggest lists?! danwellman over 8 years ago
danwellman 5600
0
points

Your tables aren't currently nested, which it will need to if you want to use sub tables.

Try this instead:

<table class='table'>
<tr>
<td>cell 1
    <table class='sub table'>
        <tr><td>data1</td><td>data2</td><td>data3</td></tr>
        <tr><td>data1</td><td>data2</td><td>data3</td></tr>
        <tr><td>data1</td><td>data2</td><td>data3</td></tr>
    </table>
</td>
<td>cell 2</td>
<td>cell 3</td>
</tr>
</table>

etc...

not sure about the styling you'll need at this point, but it's certainly how you'll want to structure your mark-up for nested tables

Answered over 8 years ago by danwellman