diff --git a/inst/htmlwidgets/lib/datatables-extensions/Buttons/js/dataTables.buttons.min.js b/inst/htmlwidgets/lib/datatables-extensions/Buttons/js/dataTables.buttons.min.js index f873dfbe..81a6476f 100644 --- a/inst/htmlwidgets/lib/datatables-extensions/Buttons/js/dataTables.buttons.min.js +++ b/inst/htmlwidgets/lib/datatables-extensions/Buttons/js/dataTables.buttons.min.js @@ -325,6 +325,62 @@ d(this).removeClass(b).remove() }) }; + /* ----- BEGIN added Code ----- */ + getHeaders = function( dt ){ + var thRows = dt.nTHead.rows; + var numRows = thRows.length; + var matrix = []; + + // Iterate over each row of the header and add information to matrix. + for ( var rowIdx = 0; rowIdx < numRows; rowIdx++ ) { + var $row = $(thRows[rowIdx]); + + // Iterate over actual columns specified in this row. + var $ths = $row.children("th"); + for ( var colIdx = 0; colIdx < $ths.length; colIdx++ ) + { + var $th = $($ths.get(colIdx)); + var colspan = $th.attr("colspan") || 1; + var rowspan = $th.attr("rowspan") || 1; + var colCount = 0; + + // ----- add this cell's title to the matrix + if (matrix[rowIdx] === undefined) { + matrix[rowIdx] = []; // create array for this row + } + // find 1st empty cell + for ( var j = 0; j < (matrix[rowIdx]).length; j++, colCount++ ) { + if ( matrix[rowIdx][j] === "PLACEHOLDER" ) { + break; + } + } + var myColCount = colCount; + matrix[rowIdx][colCount++] = $th.text(); + + // ----- If title cell has colspan, add empty titles for extra cell width. + for ( var j = 1; j < colspan; j++ ) { + matrix[rowIdx][colCount++] = ""; + } + + // ----- If title cell has rowspan, add empty titles for extra cell height. + for ( var i = 1; i < rowspan; i++ ) { + var thisRow = rowIdx+i; + if ( matrix[thisRow] === undefined ) { + matrix[thisRow] = []; + } + // First add placeholder text for any previous columns. + for ( var j = (matrix[thisRow]).length; j < myColCount; j++ ) { + matrix[thisRow][j] = "PLACEHOLDER"; + } + for ( var j = 0; j < colspan; j++ ) { // and empty for my columns + matrix[thisRow][myColCount+j] = ""; + } + } + } + } + return matrix; + }; + /*END added code*/ l.instanceSelector = function(a, b) { if (!a) return d.map(b, function(a) { return a.inst @@ -702,6 +758,9 @@ var d = b.column(a).header(); return c.format.header(d.innerHTML, a, d) }).toArray(), + /*BEGIN ADD*/ + headerMatrix = getHeaders( b.settings()[0] ) + /*END ADD*/ g = b.table().footer() ? b.columns(c.columns).indexes().map(function(a) { var d = b.column(a).footer(); @@ -713,12 +772,12 @@ }, h)).any() && d.extend(h, { selected: !0 }); - for (var h = b.rows(c.rows, h).indexes().toArray(), f = b.cells(h, c.columns), h = f.render(c.orthogonal).toArray(), f = f.nodes().toArray(), k = a.length, j = [], l = 0, n = 0, o = 0 < k ? h.length / k : 0; n < o; n++) { + for (var h = b.rows(c.rows, h).indexes().toArray(), f = b.cells(h, c.columns), h = f.render(c.orthogonal).toArray(), f = f.nodes().toArray(), f = headerMatrix[headerMatrix.length - 1].length, k = a.length, j = [], l = 0, n = 0, o = 0 < k ? h.length / k : 0; n < o; n++) { for (var r = [k], s = 0; s < k; s++) r[s] = c.format.body(h[l], n, s, f[l]), l++; j[n] = r } a = { - header: a, + header: /*a*/headerMatrix, footer: g, body: j };