Module:Tablebuilder

-- This module creates an html table using the create table method -- This is a meta-module meant to be used by other modules, but can be accessed directly. -- By Dessamator

local p = {}

--Test function to see how it works function p.testTable(frame) local sName ="newtable" local tHeader ={mamals={["data-sort-value"]="mamals", },fish={["data-sort-value"]="fish"}} local tCol = {} tCol[0]={monkey={["data-sort-value"]="trout",["style"]='color:red'}, human={["data-sort-value"]="human",["style"]='color:yellow',id='idhuman'}} tCol[1] = {shark={["data-sort-value"]="shark",["style"]='color:blue'}, cat={["data-sort-value"]="cat",["style"]='color:green'}} tCol[2] = {shark={["data-sort-value"]="tuna",["style"]='color:blue'}, dog={["data-sort-value"]="cat",["style"]='color:green'}} local tRows = {tAttribs ={["style"]="color:blue",["align"]=center},tColumnData} local tTableRows = {} for i,v in pairs(tCol) do       tTableRows[i] = {tAttribs ={["style"]="color:blue",["align"]=center},tColumns=tCol[i]} end return p.createTable(sName,tHeader,tTableRows,"",{"wikitable","sortable"}) end

--Creates table function createTable(sTableName, tHeader, tTableRows, sStyle,tClass) if not(tHeader) or not(tHeader) and not(tTableRows) then return "Error: Not enough rows to create table"; end local hTable = mw.html.create( 'table' ) if sTableName then hTable:tag('caption'):wikitext(sTableName):done; end if (tClass) then for index,sClassName in pairs(tClass) do           hTable:addClass(sClassName); end end if(sStyle) then hTable:cssText((sStyle)) end local sTableHeader= mw.html.create('tr'); for sHeader, tColumnData in pairs(tHeader) do        local sHeadingCol = mw.html.create('th') :wikitext(sHeader) :attr(tColumnData ):done; sTableHeader:node(sHeadingCol) end sTableHeader:done hTable:node(sTableHeader); local sTableRow; for sIndexKey,tRowData in pairs(tTableRows) do       local tColumns = tRowData.tColumns local tRowAttribs = tRowData.tAttribs sTableRow = mw.html.create('tr') sTableRow:attr(tRowAttribs ):done; for sKey, tColumnData in pairs(tColumns) do            local sHeadingCol = mw.html.create('td') :wikitext(sKey) :attr(tColumnData ):done; sTableRow :node(sHeadingCol ) end sTableRow :done hTable:node(sTableRow ) end hTable:done; return hTable; end

return p