7. Nested Tables

In this chapter, you will learn how to insert new columns into an existing table. You will see that columns may contain, apart from simple data types such as numbers and strings, also complex types such as entire nested tables.
Take our example with the CD store. Suppose you wish to record orders of titles that are currently out of stock. Every order should include the customer’s name and the number of ordered copies (in real life, you would also need to record the customer’s address and other details, but we will look at this later on). Obviously there may be multiple customers interested in a single sold-out album, so it is not enough to insert columns customer and pieces into the table. You will need to insert a column called order that will contain one table of orders for every album. To do this, follow these steps:
In the table header, right-click the column next to which you wish to insert the new column. In the context menu, select the New Column… option.
In the dialog window, leave the Column insertion level set to Data, type order in the Name field, and set the Data type to Table, sequence.
New options containing the settings of the nested table will appear in the dialog window. Fill in only the Structure items table defining the columns of the new table: add column name of the String type and column pieces of the Integer number type.
Click the OK button to insert the new column into the table. The contents of all cells in the column are initially folded, and only information about the number of the nested table rows is displayed (initially 0). You can unfold the folded table by clicking the plus sign ( ) on the left (or by pressing Ctrl and + on the numeric keypad). Then you can insert rows into the nested table in the usual way. Analogically, you can fold the nested table again so that it does not occupy too much space on the screen.
Note: if you switch on the summary of a table that contains nested tables (by the button), specific summaries are displayed for individual nested tables, as well. If the nested table is folded, its summary is displayed in addition to the number of rows.
A document containing a modified table populated with data is stored in file Examples\Chapter 07.s-d.