Class table

Description

Table.

A table is a container of tablegroups. Tablegroups are in turn containers of table rows, and table rows contain table cells.

This class is predicated on the idea that tables will be built bit by bit, in a sequential manner by Php code. That is to say, you will be looping through adding to the table structure and content, row by row, and within each row, cell by cell.

Here's an example of usage. Copy and paste into a test page in order to view the result and see how it works.

$mytable = new table("test"); $mytable->autojustify(); $mytable->rowstripes("background-color:#dddddd;,background-color:#efefef;"); $mytable->setalign("center"); $mytable->setwidth("70%"); $mytable->setborder(1); $mytable->thead(); $mytable->tr(); $mytable->th("Heading 1"); $mytable->th("Heading 2", "text-align:right"); $mytable->th("Heading 3"); $mytable->tbody(); $mytable->tr(); $mytable->td("Rowspan Text"); $mytable->td_rowspan(2); $mytable->td("1234"); $mytable->td("Text"); $mytable->tr(); $mytable->td("Text"); $mytable->td("1234"); $mytable->tr(); $mytable->td("Text"); $mytable->td("Text"); $mytable->td("Text"); $mytable->tr(); $mytable->td("Colspan Text"); $mytable->td_colspan(3);

Located in /html-defs.php (line 1976)

RenderableObject
   |
   --StylableObject
      |
      --HTMLObject
         |
         --table
Direct descendents
Class Description
 class matrix A matrix is a table with no colspans or rowspans. It is an N x M
Variable Summary
 mixed $autojustify
 mixed $cellpadding
 mixed $cellspacing
 mixed $groups
 mixed $tablename
Method Summary
 table table ([string $tablename = ""], [string $css = ""])
 void append_cols ([integer $repeat = 1], [object $celltoappend = false])
 void append_row ([object $celltoappend = false], [string $group = "tbody"])
 void autojustify ([bool $mode = true])
 integer cellcount (integer $row, [string $group = "tbody"])
 bool cell_exists (integer $row, integer $col, [string $group = "tbody"])
 void clearcontent ()
 integer colcount ()
 string csv ()
 void delete_cols (integer $col)
 void delete_row (integer $row, [string $group = "tbody"])
 string get_cell (integer $row, integer $col, [string $group = "tbody"])
 object The get_row (integer $row, [mixed $group = "tbody"])
 array get_width_profile ([string $group = "tbody"])
 string html ()
 void insert_cols (integer $col, [object $celltoinsert = false])
 void insert_row (integer $row, [object $celltoinsert = false])
 void merge_cols (integer $row, integer $col, integer $span, [string $group = "tbody"])
 void merge_rows (integer $row, integer $col, integer $span, [string $group = "tbody"])
 string peek_cell (integer $row, integer $col, [string $group = "tbody"])
 void permit (mixed $agentids, integer $perm)
 void permit_cell (integer $row, integer $col, mixed $agentids, integer $perm, [string $group = "tbody"])
 bool poke_cell (integer $row, integer $col, string $content, [string $css = ""], [string $contentcss = ""], [string $group = "tbody"])
 bool poke_cellcss (integer $row, integer $col, string $css, [string $contentcss = ""], [string $group = "tbody"])
 integer rowcount ()
 void rowstripes (mixed $csslist, [string $delim = ","])
 void setnbsp ([boolean $mode = true])
 void setpadding (integer $pad, integer $space)
 void set_cell (integer $row, integer $col, object $cell, [string $group = "tbody"])
 void set_width_profile (mixed $prof, [string $group = "tbody"])
 void split_cols (integer $row, integer $col, [string $group = "tbody"])
 void split_rows (integer $row, integer $col, [string $group = "tbody"])
 void tbody ([string $css = ""])
 void td ([mixed $content = ""], [string $css = ""], [mixed $heading = false], string $text)
 void td_alignment ([string $align = ""], [string $valign = ""])
 void td_colspan ([integer $span = 1])
 void td_content ([string $text = ""], [string $css = ""])
 void td_contentcss ([string $css = ""])
 void td_css ([string $css = ""])
 void td_height ([string $height = ""])
 void td_metrics ([string $width = ""], [string $height = ""])
 void td_rowspan ([integer $span = 1])
 void td_width ([string $width = ""])
 void tfoot ([string $css = ""])
 void th ([mixed $content = ""], [string $css = ""], string $text)
 void thead ([string $css = ""])
 void th_alignment ([mixed $align = ""], [mixed $valign = ""])
 void th_colspan ([mixed $span = ""])
 void th_content ([mixed $text = ""], [mixed $css = ""])
 void th_contentcss ([mixed $css = ""])
 void th_css ([mixed $css = ""])
 void th_height ([mixed $height = ""])
 void th_metrics ([mixed $width = ""], [mixed $height = ""])
 void th_rowspan ([mixed $span = ""])
 void th_width ([mixed $width = ""])
 void tr ([string $css = ""])
 void unpermit_cell (integer $row, integer $col, mixed $agentids, integer $perm, [string $group = "tbody"])
 boolean validate ()
 integer visible_cellsincol (mixed $col, [mixed $group = "tbody"])
 integer visible_cellsinrow (integer $row, [string $group = "tbody"])
 string wml ()
Variables
Methods
Constructor table (line 2005)

Table constructor Create a new table object.

table table ([string $tablename = ""], [string $css = ""])
  • string $tablename: A required name string to identify this table.
  • string $css: The style or classname to apply to the object.
append_cols (line 2707)

Append columns onto all rows in the table.

void append_cols ([integer $repeat = 1], [object $celltoappend = false])
  • integer $repeat: Number of columns to append to table
  • object $celltoappend: Template cell to use for appending
append_row (line 2777)

Append a row onto the table.

void append_row ([object $celltoappend = false], [string $group = "tbody"])
  • object $celltoappend: Template cell to use for appending the row
  • string $group: The group (default tbody) to append the row to
autojustify (line 2218)

Set table auto-justify mode on or off.

If set to on, then when we render the table, cells will have a style automatically applied to justify numeric content to the right and non-numeric content to the left. Handy with simple data tables.

void autojustify ([bool $mode = true])
  • bool $mode: True if we should auto justify all table cells
cellcount (line 2076)

Return the number of cells in a specific row.

This is the number of physical cells, rather than the number of logical number of columns. It should be the same as the colcount() method if the table is properly formatted.

  • return: The number of cells in the row.
integer cellcount (integer $row, [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • string $group: The group to find the rows
cell_exists (line 2568)

Check if given cell exists, return True is it does.

  • return: True if given cell exists, else false.
bool cell_exists (integer $row, integer $col, [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • integer $col: The column that the cell is in
  • string $group: The group to find the rows
clearcontent (line 2132)

Clear the content from all rows in table. This sets the content of every cell in every row in every group to nullstring.

void clearcontent ()
colcount (line 2055)

Return the number of cols in this table.

This is the number of columns, rather than physical cells, any of which may be spanning multiple columns. In the case of a table which is not properly formatted, this function will return the maximum columns it finds by looking across all of the table rows.

  • return: The number of columns in the table.
integer colcount ()
csv (line 2948)

Render the table as a CSV formatted stream. This is designed to facilitate the exporting of complex tables of data as CSV format for importing into spreadsheets, or databases etc.

  • return: The table content in CSV format.
string csv ()
delete_cols (line 2719)

Remove a column from all rows in the table

void delete_cols (integer $col)
  • integer $col: Column position to remove from the table
delete_row (line 2733)

Remove a row from the table. If the template cell is not provided then a 'vanilla' cell is used.

void delete_row (integer $row, [string $group = "tbody"])
  • integer $row: Row position to remove from the table
  • string $group: The group to remove row from
get_cell (line 2533)

Return the given cell from this group

  • return: The table cell object, or false if none/not valid
string get_cell (integer $row, integer $col, [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • integer $col: The column that the cell is in (0 = first cell)
  • string $group: The group to find the rows
get_row (line 2747)

Return a given row from the table.

  • return: row reqested, or false if non-existent.
object The get_row (integer $row, [mixed $group = "tbody"])
  • integer $row: Row position to remove from the table
get_width_profile (line 2818)

Get the width profile from the table.

  • return: Width profile as an array of widths
array get_width_profile ([string $group = "tbody"])
  • string $group: The group (default tbody) to append the row to
html (line 2842)

Render the whole table as HTML If dedbugging mode is enabled and the DBG_TABLES flag is set, then we run a simple validation check, and report findings, as well as making sure the table borders are visible.

  • return: The HTML for this table.
string html ()

Redefinition of:
RenderableObject::html()
Return output suitable for normal HTML-capable device. This method must be over-ridden by a method of the same name in the descendant class which renders output to web browsers.
insert_cols (line 2694)

Insert a column into all rows in the table. If the template cell is not provided, then a 'vanilla' cell is used instead.

void insert_cols (integer $col, [object $celltoinsert = false])
  • integer $col: Column position to insert at, in the table
  • object $celltoinsert: Template cell to use for inserting
insert_row (line 2764)

Insert a row into the table. If the template cell is not provided, then a 'vanilla' cell is used instead. We insert the new row just before the given row.

void insert_row (integer $row, [object $celltoinsert = false])
  • integer $row: Row position to insert before, in the table
  • object $celltoinsert: Template cell to use for all row cells
merge_cols (line 2662)

Apply a colspan in an existing table. The row and column of the

cell which has the colspan is given. As a result the relevant spanned cells will be merged in the table. If the span goes beyond the row end, it is truncated. NB: If the spanning cell is already spanning cells, then the span will extend this by the number given.

void merge_cols (integer $row, integer $col, integer $span, [string $group = "tbody"])
  • integer $row: The anchor row for the cell merge to begin
  • integer $col: The anchor column for the cell merge
  • integer $span: The number of cells to merge
  • string $group: The group to merge cells in
merge_rows (line 2626)

Merge rows at a given cell column.

void merge_rows (integer $row, integer $col, integer $span, [string $group = "tbody"])
  • integer $row: The anchor row for the row merge to begin
  • integer $col: The column for the row merge
  • integer $span: The number of rows to merge
  • string $group: The group to merge rows in
peek_cell (line 2516)

Peek content from the given row,col cell..

  • return: The cell contents, or nullstring if none/not valid
string peek_cell (integer $row, integer $col, [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • integer $col: The column that the cell is in
  • string $group: The group to find the rows
permit (line 2016)

Set cell permissions across entire table

void permit (mixed $agentids, integer $perm)
  • mixed $agentids: List or Array of unique IDs of agents to assign the permission for
  • integer $perm: The permission or combination of perms to assign
permit_cell (line 2591)

Set permission on given table cell. Optionally specify the group which is being targetted (default table body). The specified cell will have its access permission set to the given perm.

void permit_cell (integer $row, integer $col, mixed $agentids, integer $perm, [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • integer $col: The column that the cell is in
  • mixed $agentids: List or Array of unique IDs of agents to assign the permission for
  • integer $perm: The permission of combination of perms to assign
  • string $group: The group the cell is found in (defaults to table body)
poke_cell (line 2478)

Poke some content into the given row,col cell..

  • return: True if cell exists and was poked with the content
bool poke_cell (integer $row, integer $col, string $content, [string $css = ""], [string $contentcss = ""], [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • integer $col: The column that the cell is in
  • string $content: The content to put in the cell
  • string $css: Cell css setting, or omit to not set it.
  • string $contentcss: Cell content css setting, or omit to not set it.
  • string $group: The group to find the rows
poke_cellcss (line 2498)

Poke a css class/style onto the given row,col cell..

  • return: True if cell exists and was poked with the css
bool poke_cellcss (integer $row, integer $col, string $css, [string $contentcss = ""], [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • integer $col: The column that the cell is in
  • string $css: The class or style to put on the cell
  • string $contentcss: Cell content css setting, or omit to not set it.
  • string $group: The group to find the rows
rowcount (line 2039)

Return the number of rows in this table.

  • return: The number of rows in the table.
integer rowcount ()
rowstripes (line 2228)

Define css for row striping with comma-delimted list of css. Any number of these can be added to style rows in a repeating cycle.

void rowstripes (mixed $csslist, [string $delim = ","])
  • mixed $csslist: Array OR delimited list of styles or classnames
  • string $delim: Optional delimiter char, defaults to a comma
setnbsp (line 2027)

Set nbsp setting for cells in this table

void setnbsp ([boolean $mode = true])
  • boolean $mode: mode If true, then all cells will return " " if blank.
setpadding (line 2146)

Set the table padding and spacing amounts. This sets the table 'cellpadding' and 'cellspacing' attributes, in that order.

void setpadding (integer $pad, integer $space)
  • integer $pad: Amount of cellpadding in pixels
  • integer $space: Amount of cellspacing in pixels
set_cell (line 2550)

Replace the given cell with new table cell. Returns true if ok.

void set_cell (integer $row, integer $col, object $cell, [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • integer $col: The column that the cell is in
  • object $cell: The new replacement table cell object
  • string $group: The group to find the rows
set_width_profile (line 2795)

Set a width profile across the row of cells. The profile is passed as either a string or an array. If a string, the widths should be separated by commas. The widths can be absolute pixel values or %'s, and applies these widths to the first row of the given group.

An example string might for instance be '20%,15%,65%'.

void set_width_profile (mixed $prof, [string $group = "tbody"])
  • mixed $prof: The width profile, array or comma-delimeted string
  • string $group: The group (default tbody) to append the row to
split_cols (line 2679)

Remove a colspan from an existing table. The row and column of the cell which has the colspan is given. As a result the relevant spanned cells will be removed from the table.

void split_cols (integer $row, integer $col, [string $group = "tbody"])
  • integer $row: The anchor row for the cell split to begin
  • integer $col: The anchor column for the cell split
  • string $group: The group to split cells in
split_rows (line 2641)

Split rows at a given cell column.

void split_rows (integer $row, integer $col, [string $group = "tbody"])
  • integer $row: The anchor row for the row split to begin
  • integer $col: The column for the row split
  • string $group: The group to split rows in
tbody (line 2189)

Define a new tbody table group.

void tbody ([string $css = ""])
  • string $css: Style or classname to use for the group.
td (line 2299)

Define a new standard cell for the current row.

void td ([mixed $content = ""], [string $css = ""], [mixed $heading = false], string $text)
  • string $text: Content to put in the new cell.
  • string $css: Style or classname to use for the cell.
td_alignment (line 2370)

Set the working cell alignment properties in one hit. Use this method AFTER you have defined the cell with the td() method.

void td_alignment ([string $align = ""], [string $valign = ""])
  • string $align: Horizontal alignment: 'left', 'center', 'right'.
  • string $valign: Vertical alignment: 'top', 'middle', 'bottom'.
td_colspan (line 2415)

Set the working cell colspan property. Use this method AFTER you have defined the cell with the td() method.

void td_colspan ([integer $span = 1])
  • integer $span: Number of columns this cell will span.
td_content (line 2358)

Append content to the working cell. Use this method AFTER you have defined the cell with the td() method.

void td_content ([string $text = ""], [string $css = ""])
  • string $text: Content to append to the current cell.
  • string $css: Style or classname to use for the cell content.
td_contentcss (line 2346)

Set the working cell content css properties in one hit. Use this method AFTER you have defined the cell with the td() method. This defines the style or classname to use for the cell content. This will be implemented using span tags.

void td_contentcss ([string $css = ""])
  • string $css: Style or classname to use for the cell content.
td_css (line 2333)

Set the working cell css properties. Use this method AFTER you have defined the cell with the td() method. This defines the style or classname to use for the cell. Note this is for the cell, rather than the content inside the cell.

void td_css ([string $css = ""])
  • string $css: Style or classname to use for the cell.
td_height (line 2404)

Set the working cell height property. Use this method AFTER you have defined the cell with the td() method.

void td_height ([string $height = ""])
  • string $height: Number of pixels or % height of this cell.
td_metrics (line 2382)

Set the working cell width and height properties in one hit. Use this method AFTER you have defined the cell with the td() method.

void td_metrics ([string $width = ""], [string $height = ""])
  • string $width: Number of pixels or % width of this cell.
  • string $height: Number of pixels or % height of this cell.
td_rowspan (line 2426)

Set the working cell rowspan property. Use this method AFTER you have defined the cell with the td() method.

void td_rowspan ([integer $span = 1])
  • integer $span: Number of rows this cell will span.
td_width (line 2393)

Set the working cell width property. Use this method AFTER you have defined the cell with the td() method.

void td_width ([string $width = ""])
  • string $width: Number of pixels or % width of this cell.
tfoot (line 2197)

Define a new tfoot table group.

void tfoot ([string $css = ""])
  • string $css: Style or classname to use for the group.
th (line 2319)

Define a new heading cell for the current row.

void th ([mixed $content = ""], [string $css = ""], string $text)
  • string $text: Content to put in the new heading cell.
  • string $css: Style or classname to use for the cell.
thead (line 2181)

Define a new thead table group.

void thead ([string $css = ""])
  • string $css: Style or classname to use for the group.
th_alignment (line 2439)

Alias for td_alignment()

void th_alignment ([mixed $align = ""], [mixed $valign = ""])
th_colspan (line 2447)

Alias for td_colspan()

void th_colspan ([mixed $span = ""])
th_content (line 2437)

Alias for td_content()

void th_content ([mixed $text = ""], [mixed $css = ""])
th_contentcss (line 2435)

Alias for td_contentcss()

void th_contentcss ([mixed $css = ""])
th_css (line 2433)

Alias for td_css()

void th_css ([mixed $css = ""])
th_height (line 2445)

Alias for td_height()

void th_height ([mixed $height = ""])
th_metrics (line 2441)

Alias for td_metrics()

void th_metrics ([mixed $width = ""], [mixed $height = ""])
th_rowspan (line 2449)

Alias for td_rowspan()

void th_rowspan ([mixed $span = ""])
th_width (line 2443)

Alias for td_width()

void th_width ([mixed $width = ""])
tr (line 2286)

Define a new row for the current group.

void tr ([string $css = ""])
  • string $css: Style or classname to use for the row.
unpermit_cell (line 2610)

Unset permission on given table cell. Optionally specify the group which is being targetted (default table body). The specified cell will have its access permission unset from the given perms.

void unpermit_cell (integer $row, integer $col, mixed $agentids, integer $perm, [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • integer $col: The column that the cell is in
  • mixed $agentids: List or Array of unique IDs of agents to unassign the permission for
  • integer $perm: The permission of combination of perms to unassign
  • string $group: The group the cell is found in (defaults to table body)
validate (line 2243)

Check the table cell balance. Ie. make sure we have the

same number of cells in each row, taking account of rowspan and of course colspan. NB: Complex mixtures of col and row spanning will not be coped with - this is currently a very simplistic algorithm, intended for fairly basic structures.

  • return: True if the table checks out ok, else false
boolean validate ()
visible_cellsincol (line 2118)

Return the number of visible cells in a specific column.

This is the number of viewed cells, rather than the number of physical cells. Ie. if there is a rowspan of 2, then only 1 cell will be counted for it, since only one cell appears in the rendered table.

  • return: The number of visible cells in the given column.
integer visible_cellsincol (mixed $col, [mixed $group = "tbody"])
visible_cellsinrow (line 2098)

Return the number of visible cells in a specific row.

This is the number of viewed cells, rather than the number of physical columns. Ie. if there is a colspan of 2, then only 1 cell will be counted for it, since only one cell appears in the rendered table.

  • return: The number of visible cells in the row.
integer visible_cellsinrow (integer $row, [string $group = "tbody"])
  • integer $row: The row that the cell is in (0 = first row)
  • string $group: The group to find the rows
wml (line 2831)

Render as WML.

  • return: The table as WML.
string wml ()

Redefinition of:
RenderableObject::wml()
Return output suitable for normal wap-capable device. This method must be over-ridden by a method of the same name in the descendant class which renders output to wap devices.

Inherited Methods

Inherited From HTMLObject

 HTMLObject::HTMLObject()
 HTMLObject::inherit_attributes()
 HTMLObject::setaccesskey()
 HTMLObject::setalign()
 HTMLObject::setalt()
 HTMLObject::setbackground()
 HTMLObject::setbgcolor()
 HTMLObject::setborder()
 HTMLObject::setcolor()
 HTMLObject::setheight()
 HTMLObject::sethspace()
 HTMLObject::setlang()
 HTMLObject::setlangdir()
 HTMLObject::setname()
 HTMLObject::setsize()
 HTMLObject::setsrc()
 HTMLObject::settabindex()
 HTMLObject::settarget()
 HTMLObject::settitle()
 HTMLObject::setvalign()
 HTMLObject::setvspace()
 HTMLObject::setwidth()
 HTMLObject::set_attribute()
 HTMLObject::set_linkover_text()
 HTMLObject::set_onblur()
 HTMLObject::set_onchange()
 HTMLObject::set_onclick()
 HTMLObject::set_ondblclick()
 HTMLObject::set_onfocus()
 HTMLObject::set_onkeydown()
 HTMLObject::set_onkeypress()
 HTMLObject::set_onkeyup()
 HTMLObject::set_onload()
 HTMLObject::set_onmousedown()
 HTMLObject::set_onmousemove()
 HTMLObject::set_onmouseout()
 HTMLObject::set_onmouseover()
 HTMLObject::set_onmouseup()
 HTMLObject::set_onselect()
 HTMLObject::set_tabindex()
 HTMLObject::taghtml()

Inherited From StylableObject

 StylableObject::StylableObject()
 StylableObject::clearstyle()
 StylableObject::setclass()
 StylableObject::setcss()
 StylableObject::setid()
 StylableObject::setstyle()

Inherited From RenderableObject

 RenderableObject::RenderableObject()
 RenderableObject::html()
 RenderableObject::render()
 RenderableObject::wml()
 RenderableObject::wmlup()
 RenderableObject::xml()

Documentation generated by phpDocumentor 1.3.0RC3