Back to Programmer's Guide

Tables

 

Table building easy

Tables can be very difficult to do if you don't have intelligent support for making them. Study AIDA/Web approach for making tables easy to build by looking at this example:

| e |
e := WebElement new.
e cell addText: '1st cell'.
e newCell addText: '2nd cell'.
e newRow.
e cell addText: '1st cell'.
e newCell addText: '2nd cell'.
^e

This results in a table with two columns and two rows. Normally you would have to compose such a table in this way:

| table row cell |
table := WebTable new.
row := WebTableRow new.
cell := WebTableCell new addText: '1st cell'.
row add: cell.
cell := WebTableCell new addText: '2nd cell'.
row add: cell.
table add: row.
row := WebTableRow new.
cell := WebTableCell new addText: '1st cell'.
row add: cell.
cell := WebTableCell new addText: '2nd cell'.
row add: cell.
table add: row.
^table

Nesting tables

One nice feature of Aida's table support is also simple nesting of tables. Example will show that the best. Here we are buiding two horizontal tables in outer one. Outer table is also 100% wide.

| e |
e := WebElement new.
e table width: 1 "100%"
e cell table width: 1. "left table"
e cell cell addText: '1st cell'.
e cell newRow.
e cell cell addText: '2nd cell'.
e newCell table width: 1. "right table"
e cell cell addText: '1st cell'.
e cell newRow.
e cell cell addText: '2nd cell'.
^e

WebElement convenient methods

WebElement tables

  • table - return a current web table. If not yet exist, create it.
  • row - return a current table row.
  • cell - return a current table cell.
  • newTable - add a new table to this element. Return a new WebTable so that you can send messages to it immediatelly - color, width etc. Also reset current row and current cell to a new ones.
  • newRow - add a new row to current table. Return a new WebTableRow so that you can send messages to it immediatelly - color, width etc. Also reset current row and current cell to a new ones.
  • newCell - add a new cell to current table row. Return a new WebTableCell so that you can send messages to it immediatelly - color, width, addText etc.
  • initTable - clear all table information.