In this article, the first one in a four-part series, I show you how you can create a three-dimensional HTML table. I assume you have basic knowledge of HTML, DOM and JavaScript.
The HTML table as defined in the HTML specification is a two-dimensional object. In other words, the specification does not define a 3D table. The 2D table defined works like this:
Cell, Cell, Cell, Cell, Cell
Cell, Cell, Cell, Cell, Cell
Cell, Cell, Cell, Cell, Cell
Cell, Cell, Cell, Cell, Cell
Cell, Cell, Cell, Cell, Cell
Cell, Cell, Cell, Cell, Cell
There are several ways you can create a 3D HTML table. I will show you the way I find most convenient.
Now, you can decide to have only one HTML element and no text, as content for each of the above cells. That is:
Table, Table, Table, Table, Table
Table, Table, Table, Table, Table
Table, Table, Table, Table, Table
Table, Table, Table, Table, Table
Table, Table, Table, Table, Table
Table, Table, Table, Table, Table
Now, let us allow only one row for each of the tables above. That is
Row, Row, Row, Row, Row
Row, Row, Row, Row, Row
Row, Row, Row, Row, Row
Row, Row, Row, Row, Row
Row, Row, Row, Row, Row
Row, Row, Row, Row, Row
These rows are going into the page, forming the third dimension.
In the above illustrations (grids), there are six rows and five columns in what you are seeing.
So my 3D table is the normal 2D table where the content of each table cell is a one-row table. The 3D table consists of cells arranged in a 3D grid. It is the cells of the one-row tables that can take arbitrary content; each cell in the 2D table has only one item for its content, the one-row table.
Irregular 3D Table
The rows in the one-row tables can be of different lengths. If that is the case, the back of the 3D table will be irregular, so the 3D table as a whole will also be irregular.
Regular 3D Table
If the rows of the one-row tables are of the same length, then the back of the 3D table will be flat. In that case you will have a cuboid, a regular 3D table. For the rest of the article, I will talk about 3D tables that are cuboids. The size (number of cells) of such a table is given by
Y x X x Z
where Y is the number of rows in the 2D table, X is the number of columns in the 2D table and Z is the number of cells in each row in the one-row tables.
The Planes
The cells can be considered to be at the intersection points of the vertical and horizontal planes. The vertical planes I am referring to are the planes as seen from the front, placed one behind the other into the page.
Seeing Only One Plane at a Time
Even though we have a 3D table, we have but a 2D screen. Only the contents of one vertical plane should be seen at a time. For the contents of the planes whose cells are not seen, the cells are each given the value of "none" for the CSS display property. For the contents of the planes whose cells are seen, the cells are each given the value of "block" for the CSS display property.
Index Identifiers
There are no official identifiers for the indices (corresponding to Y, X, Z). I use i to identify any row in the 2D table, j to identify any column in the 2D table and k to identify any index of a cell in a one-row table.
IDs
The one-row tables must have IDs. The other elements in the 3D table do not need to have IDs. However, I have given IDs to all the elements in the example in this article. The IDs follow the order of the index identifiers (i, j, k) that I explained above.