Module:DynamicTable: Difference between revisions

From TwogPedia
No edit summary
No edit summary
 
Line 29: Line 29:
for i = 1, #split do
for i = 1, #split do
local td = mw.html.create('td'):wikitext(mw.text.trim(split[i]))
local td = mw.html.create('td'):wikitext(mw.text.trim(split[i]))
         if #split == 1 then td:attr('colspan',5) end
         if #split == 1 then td:attr('colspan',5):addClass('fw-600') end
row:node(td)
row:node(td)
end
end

Latest revision as of 10:00, 24 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]))
        if #split == 1 then td:attr('colspan',5):addClass('fw-600') end
		row:node(td)
	end
	
	return row
end

return DynamicTable