Skip to content

dokuwiki api tables

LarsGit223 edited this page Jun 30, 2016 · 10 revisions

This section describes creation of tables.

Simple table functions

These are the basic table functions with a predefined style. These are also called for basic DokuWiki rendering and therefore the function declarations need to match the class Doku_Renderer.

table_open($maxcols = NULL, $numrows = NULL, $pos = NULL)

The function opens a table. $maxcols specifies the number of columns. Parameters $numrows and $pos are unused.

table_close($pos = NULL)

The function closes a table. Parameter $pos is unused.


tablerow_open()

The function opens a new table row.

tablerow_close()

The function closes a table row.


tableheader_open($colspan = 1, $align = "left", $rowspan = 1)

The function opens a new table header cell. The cell will span $colspan columns and $rowspan rows. The content in the cell will be aligned according to $align ('left', 'center' or 'right').

tableheader_close()

The function closes a table header cell.


tablecell_open($colspan = 1, $align = "left", $rowspan = 1)

The function opens a new table cell. The cell will span $colspan columns and $rowspan rows. The content in the cell will be aligned according to $align ('left', 'center' or 'right').

tablecell_close()

The function closes a table header cell.


Code examples for simple table functions

Simple table with 2 columns

The following code:

    $renderer->table_open(2);

    $renderer->tablerow_open(1);
    $renderer->tablecell_open();
    $renderer->cdata('Cell 1/1');
    $renderer->tablecell_close();
    $renderer->tablecell_open();
    $renderer->cdata('Cell 1/2');
    $renderer->tablecell_close();
    $renderer->tablerow_close(1);

    $renderer->tablerow_open(1);
    $renderer->tablecell_open();
    $renderer->cdata('Cell 2/1');
    $renderer->tablecell_close();
    $renderer->tablecell_open();
    $renderer->cdata('Cell 2/2');
    $renderer->tablecell_close();
    $renderer->tablerow_close(1);

    $renderer->table_close(2);

generates a table with 2 columns and 2 rows.

Simple table with a header

The following code:

    $renderer->table_open(2);

    $renderer->tablerow_open(1);
    $renderer->tableheader_open();
    $renderer->cdata('Header cell 1/1');
    $renderer->tableheader_close();
    $renderer->tableheader_open();
    $renderer->cdata('Header cell 1/2');
    $renderer->tableheader_close();
    $renderer->tablerow_close(1);

    $renderer->tablerow_open(1);
    $renderer->tablecell_open();
    $renderer->cdata('Cell 2/1');
    $renderer->tablecell_close();
    $renderer->tablecell_open();
    $renderer->cdata('Cell 2/2');
    $renderer->tablecell_close();
    $renderer->tablerow_close(1);

    $renderer->table_close(2);

also generates a table with 2 columns and 2 rows but the first row is the table header.

To many columns

The following code:

    $renderer->table_open(2);

    $renderer->tablerow_open(1);
    $renderer->tableheader_open();
    $renderer->cdata('Header cell 1/1');
    $renderer->tableheader_close();
    $renderer->tableheader_open();
    $renderer->cdata('Header cell 1/2');
    $renderer->tableheader_close();
    $renderer->tableheader_open();
    $renderer->cdata('Header cell 1/3');
    $renderer->tableheader_close();
    $renderer->tablerow_close(1);

    $renderer->tablerow_open(1);
    $renderer->tablecell_open();
    $renderer->cdata('Cell 2/1');
    $renderer->tablecell_close();
    $renderer->tablecell_open();
    $renderer->cdata('Cell 2/2');
    $renderer->tablecell_close();
    $renderer->tablecell_open();
    $renderer->cdata('Cell 2/3');
    $renderer->tablecell_close();
    $renderer->tablerow_close(1);

    $renderer->table_close(2);

also generates a table with 3 columns and 2 rows. Please notice the opening of the table: $renderer->table_open(2);. The table was opened declaring only 2 columns but all 3 columns are rendered beautifully. This will not work with older versions of the ODT plugin.

Clone this wiki locally