             return len
 
         #the first few rows are for col headers
+        thead = document.createElement("thead")
         for own j, c of colAttrs
             tr = document.createElement("tr")
             if parseInt(j) == 0 and rowAttrs.length != 0

                th.className = "pvtTotalLabel"
                th.innerHTML = opts.localeStrings.totals
            tr.appendChild th
            result.appendChild tr

        #now the actual data rows, with their row headers and totals
        for own i, rowKey of rowKeys
            tr = document.createElement("tr")
            for own j, txt of rowKey

            td.setAttribute("data-value", val)
            td.setAttribute("data-for", "row"+i)
            tr.appendChild td
            tbody.appendChild tr

        #finally, the row for col totals, and a grand total
        tr = document.createElement("tr")
