Module:DynamicTable

From TwogPedia
Revision as of 10:55, 3 May 2023 by Couchor (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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