Nesting Tables


You can embed one table in another. This is called nesting. In the following example three tables are nested within one master table. The nested tables are created in the same way as the master table using the class os_table . After the three nested tables are defined, they are added as data elements to the original table.

The master table consists of two columns and three rows. A caption is added to the top of the table using function os_table::caption() .

The nested tables consist of two rows with three columns and are placed in the second column of each row of the master table. The nested tables have no borders, thus hiding the fact that they are tables.

Example <ospace/web/examples/table4 .cpp>
#include <iostream.h>
#include <ospace/web.h>

int main()
  {
  os_page page( "Table#4 Example" );

  // Nested herding dog table
  os_table_row herd_row1;
  herd_row1 << os_table_header( "Australian Cattle Dog" )
            << os_table_header( "German Shepherd" )
            << os_table_header( "Welsh Corgi" );

  os_table_row herd_row2( os_table_row::center, os_table_row::middle );
  herd_row2 << "June 12, 1979"
            << "February 11, 1978"
            << "December 13, 1994";

  os_table herding;
  herding.width( "100%" );
  herding << herd_row1 << herd_row2;

  // Nested sporting dog table
  os_table_row sport_row1;
  sport_row1 << os_table_header( "English Setter" )
             << os_table_header( "Golden Retriever" )
             << os_table_header( "Pointer" );

  os_table_row sport_row2( os_table_row::center, os_table_row::middle );
  sport_row2 << "November 11, 1986"
             << "October 13, 1981"
             << "November 11, 1975";

  os_table sporting;
  sporting.width( "100%" );
  sporting << sport_row1 << sport_row2;

  // Nested working dog table
  os_table_row work_row1;
  work_row1 << os_table_header( "Akita" )
            << os_table_header( "Great Dane" )
            << os_table_header( "Mastiff" );

  os_table_row work_row2( os_table_row::center, os_table_row::middle );
  work_row2 << "December 12, 1972"
            << "September 11, 1990"
            << "November 12, 1991";

  os_table working;
  working.width( "100%" );
  working << work_row1 << work_row2;

  // Top-level table
  os_table_row row1;
  os_table_row row2;
  os_table_row row3;
  row1 << os_table_header( "Herding" ) << herding;
  row2 << os_table_header( "Sporting" ) << sporting;
  row3 << os_table_header( "Working" ) << working;

  os_table table;
  table.caption( "Original AKC Approval Dates for Certain Dog Breeds" );
  table.border( 5 ).cell_spacing( 5 ).cell_padding( 3 ).width( "100%" );
  table << row1 << row2 << row3;

  page << table;
  cout << page;
  return 0;
  }

 


Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.