FANDOM


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:

  1. Import the module:
    local tableBuilder = require("Module:Tablebuilder")
  2. Create a lua table containing rows and columns:
    -- Array consisting of rows and columns
    local tRowData = {
    -- Row - Columns
       {"Girls","Boys"},
       {"Xena","Hercules"},
       {"Athena","Hades"},
    }
  3. Create a new table builder and pass through the tRowData:
    local newTable = tableBuilder.new(tRowData)
  4. Display the table:
    local tableOutput = newTable:getTable()

Module information

Functions

tableModel.new

Creates table model.
Parameters
NameTypepurpose
arrTabletableA Two dimensional array of the table ,e.g. {{'header','header2'},{"cell1","cell2"}}.
sTableDescriptionstringCaption of the table (e.g."green").
sStylestringTable style ( e.g. sStyle="color:green").
tClasstable- Table classes (e.g. {"wikitable","sortable"}).
Return typeReturn purpose
tablea tablemodel "class" that allows users to create tables.

self:getAttribs

Outputs the attributes of a html table.
Parameters
NameTypepurpose
iRownumberRow number.
iColnumberColumn number.
Return typeReturn purpose
tableattributes for a specific cell (row + col).

self:setCellAttr

Sets an attribute to a cell.
Parameters
NameTypepurpose
iRownumberRow number.
iColnumberColumn number.
oCellAttributestableAttributes to be set, a single string attribute or many as a table.
oAttrValstringattribute to be set.

self:setCell

Sets a value to a cell.
Parameters
NameTypepurpose
sValuestringValue to be set to a table.
iRownumberRow number.
iColnumberColumn number.
formattingtableFormatting to be set, e.g. {"style"="color:red"}.
headerbooleanSets this cell to a header (true to set, false to remove).

self:setTable

Imports a lua table, changes it to an html table.
Parameters
NameTypepurpose
arrInputtableTable two dimensional (e.g. {{'f','z'}}).

self:setData

Sets data to a cell.
Parameters
NameTypepurpose
iRownumberRow number.
iColnumberColumn number.
sFieldstringinternal table field to set data.
sNewValuestringnew value.

self:getCell

Gets a cell from a table.
Parameters
NameTypepurpose
iRownumberRow number.
iColnumberColumn number.
Return typeReturn purpose
tableattributes for a specific cell (row + col).

self:setCellStyle

Sets the style of a cell.
Parameters
NameTypepurpose
iRownumberRow number.
iColnumberColumn number.
sCellStylestringCell style, e.g. ("color").
sAttrValstringCell attribute, e.g. ("blue").

self:setCellHeader

Sets a cell as a header.
Parameters
NameTypepurpose
iRownumberRow number.
iColnumberColumn number.
bHeaderbooleantrue if header.

createRow

Creates a row.
Parameters
NameTypepurpose
tFormattingstringFormatting to be set, e.g. {"style"="color:red"}.).
Return typeReturn purpose
tableA mw.html node containing a row.

appendRow

Appends a row to a table.
Parameters
NameTypepurpose
hTabletablehTable mw.html table node --e.g. mw.html.create('table')).
tFormattingtable{["style"]="color:green"}.
Return typeReturn purpose
tableA full mw.html table.

createCol

Creates a new column.
Parameters
NameTypepurpose
sColValuestringValue of table column.
tFormattingtableFormatting to be set, e.g. {"style"="color:red"}.
bHeaderbooleanReturns true if header.
Return typeReturn purpose
tableA full mw.html node containing a "td".

appendCol

Appends a column cell to a row.
Parameters
NameTypepurpose
hColumntableA mw.html node containing a column (html th).
hTableRowtableA mw.html node containing a cell (html td).
tFormattingtableFormatting to be set, e.g. {"style"="color:red"}.
Return typeReturn purpose
stringAn error if the table is invalid or nil if not.

self:getTable

Outputs the html table.
Return typeReturn purpose
tableAn 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 typeReturn purpose
stringtext representation of the table.

self:setTableFormat

Sets the styling of a table.
Parameters
NameTypepurpose
sTableDescriptionstringDescription or caption of the table.
sStylestringthe styles (e.g. "color:green").
tClasstablethe css classes the table will use (e.g.{"bluetable","greentext"}.

self:setRowFormat

Sets the formatting of a table.
Parameters
NameTypepurpose
iRownumberThe row to add the styling.
tFormattingtableFormatting to be set, e.g. {"style"="color:red"}.

self:addRow

Adds a new row to a table.
Parameters
NameTypepurpose
iRownumberThe index of the row to add.

self:removeRow

Removes a row from the table.
Parameters
NameTypepurpose
iRownumberThe index of the row to remove.

self:setRow

Sets the contents of a row.
Parameters
NameTypepurpose
iRownumberThe index of the row to set.
tTabletablecontents (e.g. {2,3}).

self:addCol

Adds a new column to the table.
Parameters
NameTypepurpose
sColNamestringName of the column.
iColnumberThe index of the column to set.

self:removeCol

Removes a new column to the table.
Parameters
NameTypepurpose
iColnumberThe index of the column to remove.

self:getRowCount

Gets number of rows in table.
Return typeReturn purpose
numberNumber of rows.

self:getColCount

Gets number of columns in table.
Return typeReturn purpose
numberNumber of columns.

initialize

Initializes the tablebuilder (internal use).

p.new

Create a new table builder.
Parameters
NameTypepurpose
arrExtDatatableA two dimensional array containing a table e.g {{"Girls","Boys"},{"Xena","Hercules"}}.
sTableDescriptionstringA caption for the table e.g. "Table of boys and girls.
sStylestringBasic styling for the table e.g. "background:green".
tClasstableCSS classes for the whole table e.g. {"boysandgirls","red"}.
Community content is available under CC-BY-SA unless otherwise noted.

Fandom may earn an affiliate commission on sales made from links on this page.

Stream the best stories.

Fandom may earn an affiliate commission on sales made from links on this page.

Get Disney+