From e9b50d9cbcdfab60d7feb00402579dff0a8ec745 Mon Sep 17 00:00:00 2001 From: Scott Aslan Date: Wed, 5 Aug 2015 22:53:10 +0000 Subject: [PATCH] enhance pivot table element to be well formed --- dist/pivot.js | 10 +++++++--- pivot.coffee | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/dist/pivot.js b/dist/pivot.js index d5802f3e..b8eba786 100644 --- a/dist/pivot.js +++ b/dist/pivot.js @@ -730,12 +730,12 @@ return PivotData; })(); - + /* Default Renderer for hierarchical table layout */ pivotTableRenderer = function(pivotData, opts) { - var aggregator, c, colAttrs, colKey, colKeys, defaults, i, j, r, result, rowAttrs, rowKey, rowKeys, spanSize, td, th, totalAggregator, tr, txt, val, x; + var aggregator, c, colAttrs, colKey, colKeys, defaults, i, j, r, result, rowAttrs, rowKey, rowKeys, spanSize, thead, tbody, td, th, totalAggregator, tr, txt, val, x; defaults = { localeStrings: { totals: "Totals" @@ -748,6 +748,8 @@ colKeys = pivotData.getColKeys(); result = document.createElement("table"); result.className = "pvtTable"; + thead = document.createElement("thead"); + tbody = document.createElement("tbody"); spanSize = function(arr, i, j) { var l, len, n, noDraw, ref, ref1, stop, x; if (i !== 0) { @@ -897,7 +899,9 @@ td.innerHTML = totalAggregator.format(val); td.setAttribute("data-value", val); tr.appendChild(td); - result.appendChild(tr); + tbody.appendChild(tr); + result.appendChild(thead); + result.appendChild(tbody); result.setAttribute("data-numrows", rowKeys.length); result.setAttribute("data-numcols", colKeys.length); return result; diff --git a/pivot.coffee b/pivot.coffee index ccac14b2..5a6e4531 100644 --- a/pivot.coffee +++ b/pivot.coffee @@ -390,6 +390,8 @@ callWithJQuery ($) -> #now actually build the output result = document.createElement("table") result.className = "pvtTable" + thead = document.createElement("thead"); + tbody = document.createElement("tbody"); #helper function for setting row/col-span in pivotTableRenderer spanSize = (arr, i, j) -> @@ -509,7 +511,9 @@ callWithJQuery ($) -> td.innerHTML = totalAggregator.format(val) td.setAttribute("data-value", val) tr.appendChild td - result.appendChild tr + tbody.appendChild tr + result.appendChild thead + result.appendChild tbody #squirrel this away for later result.setAttribute("data-numrows", rowKeys.length)