I'm looking for the specs of HTML5 in terms of tables. I'm doing a web application has a lot of data tables.
These tables generally have one database row mapped to one table row. All is good. However one particular problem child has so many columns that it needs to be spread over two rows in the table. So the ordinary tables are (in pseudo):
<table>
<thead>
<tr>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data</td>
</tr>
</tbody>
</table>
And the problematic row are like this:
<table>
<tbody>
<tr>
<th>Header row 1</th>
</tr>
<tr>
<td>Data</td>
</tr>
<tr>
<th>Header row 2</th>
</tr>
<tr>
<td>Data</td>
</tr>
</tbody>
</table>
So my question is now: Is it valid to have nested tables in HTML5? We can easily agree that it's very ugly. But I'm considering only validity here.
If I can have nested tables, it will solve any number of problems pertaining to sorting and editing of these tables (have a semi data-grid functionality implemented). That way the main table can still consist of just one row with two columns. the sortable date and the embedded table with the data.
What do you say? I've been looking for the specs but couldn't find anything definite.
You can create nested tables to any number of levels; just remember to create an inner table inside the same cell. Below is an interpretation of nested tables.
HTML supports this functionality and is known as the nesting of the tables. Tables can be nested together to create a table inside a table. To create a nested table, we need to create a table using the <table> tag.
You cannot have a table inside another table at the back end.
This document, which contains nothing but a nested table:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A nested table</title>
</head>
<body>
<table>
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>Nested</td>
<td>Table</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
…is valid, according to http://validator.w3.org/nu/:
The document validates according to the specified schema(s) and to additional constraints checked by the validator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With