Public Member Functions | |
__construct ($autoFirstRow=true) | |
Creates new table. | |
addData ($data) | |
Adds a 2d array of data to the table. | |
addRow ($id="", $class="") | |
Adds a new row to the table. | |
getRowId ($rowIdx) | |
Retrieves row ID associated with given row. |
The table does not support cells spanning multiple rows and columns. For that, use https:://wiki.shodor.org/index.php/TKAdvTable. The table has two slots, one for the header cells and one for everything else (but see note below). Header cells have a different CSS class and style than normal cells. As you add components as normal cells, they will fill one run. The add new rows, call addRow() and then new components will go in a new row. If you want to access old rows, add components to specific row slots, which are named 'rowX', where X is a number from 0 to one less than the number of rows.
When building a table from XML, use the <row />
tag to create a new row. It is self-closing.
If you add text with TKContainer::addText, you can add a 'style' or 'class' parameter, which is applied to the cell that contains the text. These parameters are themselves arrays, following the normal rules for style and class arrays.
The basic usage of TKTable is to first add some cells to the header slot. Since these are almost always going to be text instead of another component, it is best to use the TKContainer::addTextTo method. For example, to build a header for four columns do the following:
$table->addTextTo('header', "Column 1");
$table->addTextTo('header', "Column 2");
$table->addTextTo('header', "Column 3");
// this header spans two columns
$table->addTextTo('header', "Wide Column 4", array('colspan' => 2));
The table starts with a row already, so the first components added without specifying a slot go in this first row, from right to left. You will need to call addRow() for additional rows after that. Below is an example of constructing a table with two rows and three columns:
$table->addText('Cell (0,0)');
$table->addText('Cell (0,1)');
$table->addText('Cell (0,2)');
$table->addRow();
$table->addText('Cell (1,0)');
$table->addText('Cell (1,1)');
$table->addText('Cell (1,2)');
array
: CSS class for cells array
: CSS style for cells array
: CSS class for header cells array
: CSS style for header cells array
: CSS class for footer cells array
: CSS style for footer cells
public
, TKComponent
, multi
]: contains all header cells public
, TKComponent
, multi
]: contains all footer cells public
, TKComponent
, multi
]: there is one rowX
slot for each row, where X is a number from 0 to one less than the number of rows.
TKTable::__construct | ( | $ | autoFirstRow = true |
) |
Creates new table.
$autoFirstRow | [boolean]: if true, the constructor automatically calls addRow() to create an initial first row (this is the default) |
TKTable::addData | ( | $ | data | ) |
Adds a 2d array of data to the table.
Each element in the input array corresponds to a row in the table. If an element in the input array is itself an array, then each of its elements is added to the table as a cell in the current row. Otherwise, the element is added by itself to the current row.
$data | [array]: 2d array of data to be loaded into the table. |
TKTable::addRow | ( | $ | id = "" , |
|
$ | class = "" | |||
) |
Adds a new row to the table.
All new components are added to this row, unless explicitly specified otherwise. The new row's slot is named rowX
where X is the new number of rows minus one.
$id | [string]: XML id to assign to row, if desired (default row ID is generated otherwise) | |
$class | [string]: CSS class to set on the row |
TKTable::getRowId | ( | $ | rowIdx | ) |
Retrieves row ID associated with given row.
$rowIdx | [int]: index of row to retrieve ID for (starting from 0) |