1 var _typeof = typeof Symbol ===
"function" && typeof Symbol.iterator ===
"symbol" ?
function (obj) {
return typeof obj; } :
function (obj) {
return obj && typeof Symbol ===
"function" && obj.constructor === Symbol && obj !== Symbol.prototype ?
"symbol" : typeof obj; };
5 var HtmlTableExport =
function HtmlTableExport(table) {
8 this.cloneTableStyle =
true;
12 HtmlTableExport.prototype.genereateTable =
function (config, style, visible, colVisProp) {
13 this.cloneTableStyle = style;
14 this.config = config || {};
15 this.colVisProp = colVisProp;
17 var headers = this.generateHeaderElements();
18 var body = this.generateBodyElements(visible);
20 var table = document.createElement(
"table");
21 table.classList.add(
"tabulator-print-table");
22 table.appendChild(headers);
23 table.appendChild(body);
25 this.mapElementStyles(this.table.element, table, [
"border-top",
"border-left",
"border-right",
"border-bottom"]);
30 HtmlTableExport.prototype.generateColumnGroupHeaders =
function () {
35 var columns = this.config.columnGroups !==
false ? this.table.columnManager.columns : this.table.columnManager.columnsByIndex;
37 columns.forEach(
function (column) {
38 var colData = _this.processColumnGroup(column);
48 HtmlTableExport.prototype.processColumnGroup =
function (column) {
51 var subGroups = column.columns,
55 title: column.definition.title,
60 if (subGroups.length) {
61 groupData.subGroups = [];
64 subGroups.forEach(
function (subGroup) {
65 var subGroupData = _this2.processColumnGroup(subGroup);
68 groupData.width += subGroupData.width;
69 groupData.subGroups.push(subGroupData);
71 if (subGroupData.depth > maxDepth) {
72 maxDepth = subGroupData.depth;
77 groupData.depth += maxDepth;
79 if (!groupData.width) {
83 if (this.columnVisCheck(column)) {
93 HtmlTableExport.prototype.groupHeadersToRows =
function (columns) {
98 function parseColumnGroup(column, level) {
100 var depth = headerDepth - level;
102 if (typeof headers[level] ===
"undefined") {
106 column.height = column.subGroups ? 1 : depth - column.depth + 1;
108 headers[level].push(column);
110 if (column.subGroups) {
111 column.subGroups.forEach(
function (subGroup) {
112 parseColumnGroup(subGroup, level + 1);
118 columns.forEach(
function (column) {
119 if (column.depth > headerDepth) {
120 headerDepth = column.depth;
124 columns.forEach(
function (column) {
125 parseColumnGroup(column, 0);
131 HtmlTableExport.prototype.generateHeaderElements =
function () {
134 var headerEl = document.createElement(
"thead");
136 var rows = this.groupHeadersToRows(this.generateColumnGroupHeaders());
138 rows.forEach(
function (row) {
139 var rowEl = document.createElement(
"tr");
141 _this3.mapElementStyles(_this3.table.columnManager.getHeadersElement(), headerEl, [
"border-top",
"border-left",
"border-right",
"border-bottom",
"background-color",
"color",
"font-weight",
"font-family",
"font-size"]);
143 row.forEach(
function (column) {
144 var cellEl = document.createElement(
"th");
145 var classNames = column.column.definition.cssClass ? column.column.definition.cssClass.split(
" ") : [];
147 cellEl.colSpan = column.width;
148 cellEl.rowSpan = column.height;
150 cellEl.innerHTML = column.column.definition.title;
152 if (_this3.cloneTableStyle) {
153 cellEl.style.boxSizing =
"border-box";
156 classNames.forEach(
function (className) {
157 cellEl.classList.add(className);
160 _this3.mapElementStyles(column.column.getElement(), cellEl, [
"text-align",
"border-top",
"border-left",
"border-right",
"border-bottom",
"background-color",
"color",
"font-weight",
"font-family",
"font-size"]);
161 _this3.mapElementStyles(column.column.contentElement, cellEl, [
"padding-top",
"padding-left",
"padding-right",
"padding-bottom"]);
163 if (column.column.visible) {
164 _this3.mapElementStyles(column.column.getElement(), cellEl, [
"width"]);
166 if (column.column.definition.width) {
167 cellEl.style.width = column.column.definition.width +
"px";
171 if (column.column.parent) {
172 _this3.mapElementStyles(column.column.parent.groupElement, cellEl, [
"border-top"]);
175 rowEl.appendChild(cellEl);
178 headerEl.appendChild(rowEl);
184 HtmlTableExport.prototype.generateBodyElements =
function (visible) {
187 var oddRow, evenRow, calcRow, firstRow, firstCell, firstGroup, lastCell, styleCells, styleRow;
190 if (this.cloneTableStyle && window.getComputedStyle) {
191 oddRow = this.table.element.querySelector(
".tabulator-row-odd:not(.tabulator-group):not(.tabulator-calcs)");
192 evenRow = this.table.element.querySelector(
".tabulator-row-even:not(.tabulator-group):not(.tabulator-calcs)");
193 calcRow = this.table.element.querySelector(
".tabulator-row.tabulator-calcs");
194 firstRow = this.table.element.querySelector(
".tabulator-row:not(.tabulator-group):not(.tabulator-calcs)");
195 firstGroup = this.table.element.getElementsByClassName(
"tabulator-group")[0];
198 styleCells = firstRow.getElementsByClassName(
"tabulator-cell");
199 firstCell = styleCells[0];
200 lastCell = styleCells[styleCells.length - 1];
204 var bodyEl = document.createElement(
"tbody");
206 var rows = visible ? this.table.rowManager.getVisibleRows(
true) : this.table.rowManager.getDisplayRows();
209 if (this.config.columnCalcs !==
false &&
this.table.modExists(
"columnCalcs")) {
210 if (this.table.modules.columnCalcs.topInitialized) {
211 rows.unshift(this.table.modules.columnCalcs.topRow);
214 if (this.table.modules.columnCalcs.botInitialized) {
215 rows.push(this.table.modules.columnCalcs.botRow);
219 this.table.columnManager.columnsByIndex.forEach(
function (column) {
220 if (_this4.columnVisCheck(column)) {
221 columns.push(column);
225 rows = rows.filter(
function (row) {
228 return _this4.config.rowGroups !==
false;
232 return _this4.config.columnCalcs !==
false;
239 if (rows.length > 1000) {
240 console.warn(
"It may take a long time to render an HTML table with more than 1000 rows");
243 rows.forEach(
function (row, i) {
244 var rowData = row.getData();
246 var rowEl = document.createElement(
"tr");
247 rowEl.classList.add(
"tabulator-print-table-row");
251 var cellEl = document.createElement(
"td");
252 cellEl.colSpan = columns.length;
253 cellEl.innerHTML = row.key;
255 rowEl.classList.add(
"tabulator-print-table-group");
257 _this4.mapElementStyles(firstGroup, rowEl, [
"border-top",
"border-left",
"border-right",
"border-bottom",
"color",
"font-weight",
"font-family",
"font-size",
"background-color"]);
258 _this4.mapElementStyles(firstGroup, cellEl, [
"padding-top",
"padding-left",
"padding-right",
"padding-bottom"]);
259 rowEl.appendChild(cellEl);
263 rowEl.classList.add(
"tabulator-print-table-calcs");
266 columns.forEach(
function (column) {
267 var cellEl = document.createElement(
"td");
269 var value = column.getFieldValue(rowData);
273 getValue:
function getValue() {
276 getField:
function getField() {
277 return column.definition.field;
279 getElement:
function getElement() {
282 getColumn:
function getColumn() {
283 return column.getComponent();
285 getData:
function getData() {
288 getRow:
function getRow() {
289 return row.getComponent();
291 getComponent:
function getComponent() {
297 var classNames = column.definition.cssClass ? column.definition.cssClass.split(
" ") : [];
299 classNames.forEach(
function (className) {
300 cellEl.classList.add(className);
303 if (_this4.table.modExists(
"format")) {
304 value = _this4.table.modules.format.formatValue(cellWrapper);
306 switch (typeof value ===
"undefined" ?
"undefined" : _typeof(value)) {
308 value = JSON.stringify(value);
321 if (value instanceof Node) {
322 cellEl.appendChild(value);
324 cellEl.innerHTML = value;
328 _this4.mapElementStyles(firstCell, cellEl, [
"padding-top",
"padding-left",
"padding-right",
"padding-bottom",
"border-top",
"border-left",
"border-right",
"border-bottom",
"color",
"font-weight",
"font-family",
"font-size",
"text-align"]);
331 rowEl.appendChild(cellEl);
334 styleRow = row.type ==
"calc" ? calcRow : i % 2 && evenRow ? evenRow : oddRow;
336 _this4.mapElementStyles(styleRow, rowEl, [
"border-top",
"border-left",
"border-right",
"border-bottom",
"color",
"font-weight",
"font-family",
"font-size",
"background-color"]);
340 bodyEl.appendChild(rowEl);
346 HtmlTableExport.prototype.columnVisCheck =
function (column) {
347 return column.definition[this.colVisProp] !==
false && (column.visible || !column.visible && column.definition[this.colVisProp]);
350 HtmlTableExport.prototype.getHtml =
function (visible, style, config) {
351 var holder = document.createElement(
"div");
353 holder.appendChild(this.genereateTable(config || this.table.options.htmlOutputConfig, style, visible,
"htmlOutput"));
355 return holder.innerHTML;
358 HtmlTableExport.prototype.mapElementStyles =
function (from, to, props) {
359 if (this.cloneTableStyle && from && to) {
362 "background-color":
"backgroundColor",
363 "color":
"fontColor",
365 "font-weight":
"fontWeight",
366 "font-family":
"fontFamily",
367 "font-size":
"fontSize",
368 "text-align":
"textAlign",
369 "border-top":
"borderTop",
370 "border-left":
"borderLeft",
371 "border-right":
"borderRight",
372 "border-bottom":
"borderBottom",
373 "padding-top":
"paddingTop",
374 "padding-left":
"paddingLeft",
375 "padding-right":
"paddingRight",
376 "padding-bottom":
"paddingBottom"
379 if (window.getComputedStyle) {
380 var fromStyle = window.getComputedStyle(from);
382 props.forEach(
function (prop) {
383 to.style[lookup[prop]] = fromStyle.getPropertyValue(prop);
389 Tabulator.prototype.registerModule(
"htmlTableExport", HtmlTableExport);