(Created page with "local getArgs = require('Module:Arguments').getArgs local DynamicTable = {} function DynamicTable.main(frame) local args = getArgs(frame) local tableContainer = mw.html.create('table'):addClass('wikitable') local split = mw.text.split(args.columns, ',') local headerRow = mw.html.create('tr') for i = 1, #split do local th = mw.html.create('th'):wikitext(mw.text.trim(split[i])) headerRow:node(th) end tableContainer:node(headerRow):node(args.rows) return ta...") |
No edit summary |
||
Line 7: | Line 7: | ||
local tableContainer = mw.html.create('table'):addClass('wikitable') | local tableContainer = mw.html.create('table'):addClass('wikitable') | ||
if ( args.columns ) then | |||
local split = mw.text.split(args.columns, ',') | local split = mw.text.split(args.columns, ',') | ||
local headerRow = mw.html.create('tr') | local headerRow = mw.html.create('tr') | ||
Line 14: | Line 14: | ||
headerRow:node(th) | headerRow:node(th) | ||
end | end | ||
tableContainer:node(headerRow) | |||
end | |||
tableContainer:node(args.rows) | |||
return tableContainer | return tableContainer | ||
end | end |
Revision as of 13:02, 16 May 2023
Documentation for this module may be created at Module:DynamicTable/doc
local getArgs = require('Module:Arguments').getArgs
local DynamicTable = {}
function DynamicTable.main(frame)
local args = getArgs(frame)
local tableContainer = mw.html.create('table'):addClass('wikitable')
if ( args.columns ) then
local split = mw.text.split(args.columns, ',')
local headerRow = mw.html.create('tr')
for i = 1, #split do
local th = mw.html.create('th'):wikitext(mw.text.trim(split[i]))
headerRow:node(th)
end
tableContainer:node(headerRow)
end
tableContainer:node(args.rows)
return tableContainer
end
function DynamicTable.row(frame)
local args = getArgs(frame)
local split = mw.text.split(args[1], ',')
local row = mw.html.create('tr')
for i = 1, #split do
local td = mw.html.create('td'):wikitext(mw.text.trim(split[i]))
row:node(td)
end
return row
end
return DynamicTable