I’m currently experimenting with creation of tables in html using the DOM API (DOM)
I have this example script as space-lua:
function widget.tabletest ()
local cols = {}
local rows = {}
for colnr = 1 ,3 , 1
do
for rownr = 1, 4, 1
do
table.insert(cols,
dom.td{ rownr .. " / " .. colnr}
)
end
table.insert(rows,
dom.tr(cols)
)
cols = {}
end
return widget.new{
display = "block",
cssClasses = {"domtabletest"},
html = dom.table(rows)
}
end
This works already as expected. Now I want to use different space styles for cells and or rows.
Basically I would use something like that to add a classname:
html = dom.span(class="banana", "this is my text")
However this does not work within my loops, where I create the cols and rows.
Only within the inner loop I am able to attach a classname like this:
dom.td{class="banana", rownr .. " / " .. colnr}
But it does not work like that on the outer loop. E.g. with
dom.tr{class="banana", cols}
I get an Lua error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’.
Same if I try that within the return statement:
html = dom.table{class=“banana”,rows}
I suspect, it is how the contents of “rows” and “cols” look like, as they are already tables with dom-objects. But I can’t see what’s in there, as “print col” only prints out “{}”
Any hint how to change my script to add html classnames?
Thanks a lot!