Tablebuilder is a meta-module that makes it easier to construct HTML based tables in a wiki.
Description
This module makes use of a scribunto lua library to create, and modify tables dynamically.
Syntax
To create a simple table, follow these steps:
- Import the module:
local tableBuilder = require("Module:Tablebuilder")
- Create a lua table containing rows and columns:
-- Array consisting of rows and columns local tRowData = { -- Row - Columns {"Girls","Boys"}, {"Xena","Hercules"}, {"Athena","Hades"}, }
- Create a new table builder and pass through the tRowData:
local newTable = tableBuilder.new(tRowData)
- Display the table:
local tableOutput = newTable:getTable()
Module information
Functions
tableModel.new
Creates table model.
Parameters
| Name | Type | purpose |
|---|---|---|
| arrTable | table | A Two dimensional array of the table ,e.g. {{'header','header2'},{"cell1","cell2"}}. |
| sTableDescription | string | Caption of the table (e.g."green"). |
| sStyle | string | Table style ( e.g. sStyle="color:green"). |
| tClass | table | - Table classes (e.g. {"wikitable","sortable"}). |
| Return type | Return purpose |
|---|---|
| table | a tablemodel "class" that allows users to create tables. |
self:getAttribs
Outputs the attributes of a html table.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | Row number. |
| iCol | number | Column number. |
| Return type | Return purpose |
|---|---|
| table | attributes for a specific cell (row + col). |
self:setCellAttr
Sets an attribute to a cell.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | Row number. |
| iCol | number | Column number. |
| oCellAttributes | table | Attributes to be set, a single string attribute or many as a table. |
| oAttrVal | string | attribute to be set. |
self:setCell
Sets a value to a cell.
Parameters
| Name | Type | purpose |
|---|---|---|
| sValue | string | Value to be set to a table. |
| iRow | number | Row number. |
| iCol | number | Column number. |
| formatting | table | Formatting to be set, e.g. {"style"="color:red"}. |
| header | boolean | Sets this cell to a header (true to set, false to remove). |
self:setTable
Imports a lua table, changes it to an html table.
Parameters
| Name | Type | purpose |
|---|---|---|
| arrInput | table | Table two dimensional (e.g. {{'f','z'}}). |
self:setData
Sets data to a cell.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | Row number. |
| iCol | number | Column number. |
| sField | string | internal table field to set data. |
| sNewValue | string | new value. |
self:getCell
Gets a cell from a table.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | Row number. |
| iCol | number | Column number. |
| Return type | Return purpose |
|---|---|
| table | attributes for a specific cell (row + col). |
self:setCellStyle
Sets the style of a cell.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | Row number. |
| iCol | number | Column number. |
| sCellStyle | string | Cell style, e.g. ("color"). |
| sAttrVal | string | Cell attribute, e.g. ("blue"). |
self:setCellHeader
Sets a cell as a header.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | Row number. |
| iCol | number | Column number. |
| bHeader | boolean | true if header. |
createRow
Creates a row.
Parameters
| Name | Type | purpose |
|---|---|---|
| tFormatting | string | Formatting to be set, e.g. {"style"="color:red"}.). |
| Return type | Return purpose |
|---|---|
| table | A mw.html node containing a row. |
appendRow
Appends a row to a table.
Parameters
| Name | Type | purpose |
|---|---|---|
| hTable | table | hTable mw.html table node --e.g. mw.html.create('table')). |
| tFormatting | table | {["style"]="color:green"}. |
| Return type | Return purpose |
|---|---|
| table | A full mw.html table. |
createCol
Creates a new column.
Parameters
| Name | Type | purpose |
|---|---|---|
| sColValue | string | Value of table column. |
| tFormatting | table | Formatting to be set, e.g. {"style"="color:red"}. |
| bHeader | boolean | Returns true if header. |
| Return type | Return purpose |
|---|---|
| table | A full mw.html node containing a "td". |
appendCol
Appends a column cell to a row.
Parameters
| Name | Type | purpose |
|---|---|---|
| hColumn | table | A mw.html node containing a column (html th). |
| hTableRow | table | A mw.html node containing a cell (html td). |
| tFormatting | table | Formatting to be set, e.g. {"style"="color:red"}. |
| Return type | Return purpose |
|---|---|
| string | An error if the table is invalid or nil if not. |
self:getTable
Outputs the html table.
| Return type | Return purpose |
|---|---|
| table | An mw.html node containing the whole table. |
self:setGrid
Sets the rows and columns of table.
self:getGrid
Prints out text representation of the table.
| Return type | Return purpose |
|---|---|
| string | text representation of the table. |
self:setTableFormat
Sets the styling of a table.
Parameters
| Name | Type | purpose |
|---|---|---|
| sTableDescription | string | Description or caption of the table. |
| sStyle | string | the styles (e.g. "color:green"). |
| tClass | table | the css classes the table will use (e.g.{"bluetable","greentext"}. |
self:setRowFormat
Sets the formatting of a table.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | The row to add the styling. |
| tFormatting | table | Formatting to be set, e.g. {"style"="color:red"}. |
self:addRow
Adds a new row to a table.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | The index of the row to add. |
self:removeRow
Removes a row from the table.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | The index of the row to remove. |
self:setRow
Sets the contents of a row.
Parameters
| Name | Type | purpose |
|---|---|---|
| iRow | number | The index of the row to set. |
| tTable | table | contents (e.g. {2,3}). |
self:addCol
Adds a new column to the table.
Parameters
| Name | Type | purpose |
|---|---|---|
| sColName | string | Name of the column. |
| iCol | number | The index of the column to set. |
self:removeCol
Removes a new column to the table.
Parameters
| Name | Type | purpose |
|---|---|---|
| iCol | number | The index of the column to remove. |
self:getRowCount
Gets number of rows in table.
| Return type | Return purpose |
|---|---|
| number | Number of rows. |
self:getColCount
Gets number of columns in table.
| Return type | Return purpose |
|---|---|
| number | Number of columns. |
p.new
Initializes the tablebuilder (internal use)
Create a new table builder.
Parameters
| Name | Type | purpose |
|---|---|---|
| arrExtData | table | A two dimensional array containing a table e.g {{"Girls","Boys"},{"Xena","Hercules"}}. |
| sTableDescription | string | A caption for the table e.g. "Table of boys and girls. |
| sStyle | string | Basic styling for the table e.g. "background:green". |
| tClass | table | CSS classes for the whole table e.g. {"boysandgirls","red"}. |