                 th.className = "pvtTotalLabel"
                 th.innerHTML = opts.localeStrings.totals
             tr.appendChild th
-            result.appendChild tr
+            thead.appendChild tr
+        result.appendChild thead
 
         #now the actual data rows, with their row headers and totals
+        tbody = document.createElement("tbody")
         for own i, rowKey of rowKeys
             tr = document.createElement("tr")
             for own j, txt of rowKey

            return len

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

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