FANDOM


Tablebuilder is a meta-module that makes it easier to construct HTML based tables in a wiki.

Description Edit

This module makes use of a scribunto lua library to create, and modify tables dynamically.

Syntax Edit

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()

Install

Installing modules

To get a brief introduction to lua read the basics page first. On Wikia, one can use modules by either accessing a module remotely or copying all its contents to a Wiki. Modules accessed remotely from dev.wikia are subject to change while 'correctly' copied modules are controlled by a particular wiki.

Using a module "remotely" using Module:Devmodule

Create Module:Devmodule and copy the following code to remotely access modules in dev's repository. See more details in Global Lua Modules/Devmodule.
--[[This imports modules from dev.wikia]]
return require("Dev:Devmodule")

Loading modules remotely from dev.wikia

Create Module:Tablebuilder in your wiki and add the following code:
--This loads modules directly from dev.wikia.com
return require("Dev:Tablebuilder")

Using Module:Tablebuilder in another wiki

To use modules without depending on dev see this page. Create Template:Tablebuilder in your wiki and add the following code:
{{#invoke:Tablebuilder|main}}

Using template in a page

You can use this module in a page using syntax such as:
{{Tablebuilder|main|arg1|arg2}}

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"}.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.