Built files from Bizgaze WebServer
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

export.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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; };
  2. /* Tabulator v4.6.3 (c) Oliver Folkerd */
  3. var Export = function Export(table) {
  4. this.table = table; //hold Tabulator object
  5. this.config = {};
  6. this.cloneTableStyle = true;
  7. this.colVisProp = "";
  8. };
  9. Export.prototype.genereateTable = function (config, style, range, colVisProp) {
  10. this.cloneTableStyle = style;
  11. this.config = config || {};
  12. this.colVisProp = colVisProp;
  13. var table = document.createElement("table");
  14. table.classList.add("tabulator-print-table");
  15. if (this.config.columnHeaders !== false) {
  16. table.appendChild(this.generateHeaderElements());
  17. }
  18. table.appendChild(this.generateBodyElements(this.rowLookup(range)));
  19. this.mapElementStyles(this.table.element, table, ["border-top", "border-left", "border-right", "border-bottom"]);
  20. return table;
  21. };
  22. Export.prototype.rowLookup = function (range) {
  23. var _this = this;
  24. var rows = [];
  25. if (typeof range == "function") {
  26. range.call(this.table).forEach(function (row) {
  27. row = _this.table.rowManager.findRow(row);
  28. if (row) {
  29. rows.push(row);
  30. }
  31. });
  32. } else {
  33. switch (range) {
  34. case true:
  35. case "visible":
  36. rows = this.table.rowManager.getVisibleRows(true);
  37. break;
  38. case "all":
  39. rows = this.table.rowManager.rows;
  40. break;
  41. case "selected":
  42. rows = this.table.modules.selectRow.selectedRows;
  43. break;
  44. case "active":
  45. default:
  46. rows = this.table.rowManager.getDisplayRows();
  47. }
  48. }
  49. return Object.assign([], rows);
  50. };
  51. Export.prototype.generateColumnGroupHeaders = function () {
  52. var _this2 = this;
  53. var output = [];
  54. var columns = this.config.columnGroups !== false ? this.table.columnManager.columns : this.table.columnManager.columnsByIndex;
  55. columns.forEach(function (column) {
  56. var colData = _this2.processColumnGroup(column);
  57. if (colData) {
  58. output.push(colData);
  59. }
  60. });
  61. return output;
  62. };
  63. Export.prototype.processColumnGroup = function (column) {
  64. var _this3 = this;
  65. var subGroups = column.columns,
  66. maxDepth = 0;
  67. var groupData = {
  68. title: column.definition.title,
  69. column: column,
  70. depth: 1
  71. };
  72. if (subGroups.length) {
  73. groupData.subGroups = [];
  74. groupData.width = 0;
  75. subGroups.forEach(function (subGroup) {
  76. var subGroupData = _this3.processColumnGroup(subGroup);
  77. if (subGroupData) {
  78. groupData.width += subGroupData.width;
  79. groupData.subGroups.push(subGroupData);
  80. if (subGroupData.depth > maxDepth) {
  81. maxDepth = subGroupData.depth;
  82. }
  83. }
  84. });
  85. groupData.depth += maxDepth;
  86. if (!groupData.width) {
  87. return false;
  88. }
  89. } else {
  90. if (this.columnVisCheck(column)) {
  91. groupData.width = 1;
  92. } else {
  93. return false;
  94. }
  95. }
  96. return groupData;
  97. };
  98. Export.prototype.groupHeadersToRows = function (columns) {
  99. var headers = [],
  100. headerDepth = 0;
  101. function parseColumnGroup(column, level) {
  102. var depth = headerDepth - level;
  103. if (typeof headers[level] === "undefined") {
  104. headers[level] = [];
  105. }
  106. column.height = column.subGroups ? 1 : depth - column.depth + 1;
  107. headers[level].push(column);
  108. if (column.subGroups) {
  109. column.subGroups.forEach(function (subGroup) {
  110. parseColumnGroup(subGroup, level + 1);
  111. });
  112. }
  113. }
  114. //calculate maximum header debth
  115. columns.forEach(function (column) {
  116. if (column.depth > headerDepth) {
  117. headerDepth = column.depth;
  118. }
  119. });
  120. columns.forEach(function (column) {
  121. parseColumnGroup(column, 0);
  122. });
  123. return headers;
  124. };
  125. Export.prototype.generateHeaderElements = function () {
  126. var _this4 = this;
  127. var headerEl = document.createElement("thead");
  128. var rows = this.groupHeadersToRows(this.generateColumnGroupHeaders());
  129. rows.forEach(function (row) {
  130. var rowEl = document.createElement("tr");
  131. _this4.mapElementStyles(_this4.table.columnManager.getHeadersElement(), headerEl, ["border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
  132. row.forEach(function (column) {
  133. var cellEl = document.createElement("th");
  134. var classNames = column.column.definition.cssClass ? column.column.definition.cssClass.split(" ") : [];
  135. cellEl.colSpan = column.width;
  136. cellEl.rowSpan = column.height;
  137. cellEl.innerHTML = column.column.definition.title;
  138. if (_this4.cloneTableStyle) {
  139. cellEl.style.boxSizing = "border-box";
  140. }
  141. classNames.forEach(function (className) {
  142. cellEl.classList.add(className);
  143. });
  144. _this4.mapElementStyles(column.column.getElement(), cellEl, ["text-align", "border-top", "border-left", "border-right", "border-bottom", "background-color", "color", "font-weight", "font-family", "font-size"]);
  145. _this4.mapElementStyles(column.column.contentElement, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom"]);
  146. if (column.column.visible) {
  147. _this4.mapElementStyles(column.column.getElement(), cellEl, ["width"]);
  148. } else {
  149. if (column.column.definition.width) {
  150. cellEl.style.width = column.column.definition.width + "px";
  151. }
  152. }
  153. if (column.column.parent) {
  154. _this4.mapElementStyles(column.column.parent.groupElement, cellEl, ["border-top"]);
  155. }
  156. rowEl.appendChild(cellEl);
  157. });
  158. headerEl.appendChild(rowEl);
  159. });
  160. return headerEl;
  161. };
  162. Export.prototype.generateBodyElements = function (rows) {};
  163. Export.prototype.generateBodyElements = function (rows) {
  164. var _this5 = this;
  165. var oddRow, evenRow, calcRow, firstRow, firstCell, firstGroup, lastCell, styleCells, styleRow, treeElementField, rowFormatter;
  166. //assign row formatter
  167. rowFormatter = this.table.options["rowFormatter" + (this.colVisProp.charAt(0).toUpperCase() + this.colVisProp.slice(1))];
  168. rowFormatter = rowFormatter !== null ? rowFormatter : this.table.options.rowFormatter;
  169. //lookup row styles
  170. if (this.cloneTableStyle && window.getComputedStyle) {
  171. oddRow = this.table.element.querySelector(".tabulator-row-odd:not(.tabulator-group):not(.tabulator-calcs)");
  172. evenRow = this.table.element.querySelector(".tabulator-row-even:not(.tabulator-group):not(.tabulator-calcs)");
  173. calcRow = this.table.element.querySelector(".tabulator-row.tabulator-calcs");
  174. firstRow = this.table.element.querySelector(".tabulator-row:not(.tabulator-group):not(.tabulator-calcs)");
  175. firstGroup = this.table.element.getElementsByClassName("tabulator-group")[0];
  176. if (firstRow) {
  177. styleCells = firstRow.getElementsByClassName("tabulator-cell");
  178. firstCell = styleCells[0];
  179. lastCell = styleCells[styleCells.length - 1];
  180. }
  181. }
  182. var bodyEl = document.createElement("tbody");
  183. var columns = [];
  184. if (this.config.columnCalcs !== false && this.table.modExists("columnCalcs")) {
  185. if (this.table.modules.columnCalcs.topInitialized) {
  186. rows.unshift(this.table.modules.columnCalcs.topRow);
  187. }
  188. if (this.table.modules.columnCalcs.botInitialized) {
  189. rows.push(this.table.modules.columnCalcs.botRow);
  190. }
  191. }
  192. this.table.columnManager.columnsByIndex.forEach(function (column) {
  193. if (_this5.columnVisCheck(column)) {
  194. columns.push(column);
  195. }
  196. });
  197. if (this.table.options.dataTree && this.config.dataTree !== false && this.table.modExists("columnCalcs")) {
  198. treeElementField = this.table.modules.dataTree.elementField;
  199. }
  200. rows = rows.filter(function (row) {
  201. switch (row.type) {
  202. case "group":
  203. return _this5.config.rowGroups !== false;
  204. break;
  205. case "calc":
  206. return _this5.config.columnCalcs !== false;
  207. break;
  208. }
  209. return true;
  210. });
  211. if (rows.length > 1000) {
  212. console.warn("It may take a long time to render an HTML table with more than 1000 rows");
  213. }
  214. rows.forEach(function (row, i) {
  215. var rowData = row.getData(_this5.colVisProp);
  216. var rowEl = document.createElement("tr");
  217. rowEl.classList.add("tabulator-print-table-row");
  218. switch (row.type) {
  219. case "group":
  220. var cellEl = document.createElement("td");
  221. cellEl.colSpan = columns.length;
  222. cellEl.innerHTML = row.key;
  223. rowEl.classList.add("tabulator-print-table-group");
  224. _this5.mapElementStyles(firstGroup, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  225. _this5.mapElementStyles(firstGroup, cellEl, ["padding-top", "padding-left", "padding-right", "padding-bottom"]);
  226. rowEl.appendChild(cellEl);
  227. break;
  228. case "calc":
  229. rowEl.classList.add("tabulator-print-table-calcs");
  230. case "row":
  231. if (_this5.table.options.dataTree && _this5.config.dataTree === false && row.modules.dataTree.parent) {
  232. return;
  233. }
  234. columns.forEach(function (column, i) {
  235. var cellEl = document.createElement("td");
  236. var value = column.getFieldValue(rowData);
  237. var cellWrapper = {
  238. modules: {},
  239. getValue: function getValue() {
  240. return value;
  241. },
  242. getField: function getField() {
  243. return column.definition.field;
  244. },
  245. getElement: function getElement() {
  246. return cellEl;
  247. },
  248. getColumn: function getColumn() {
  249. return column.getComponent();
  250. },
  251. getData: function getData() {
  252. return rowData;
  253. },
  254. getRow: function getRow() {
  255. return row.getComponent();
  256. },
  257. getComponent: function getComponent() {
  258. return cellWrapper;
  259. },
  260. column: column
  261. };
  262. var classNames = column.definition.cssClass ? column.definition.cssClass.split(" ") : [];
  263. classNames.forEach(function (className) {
  264. cellEl.classList.add(className);
  265. });
  266. if (_this5.table.modExists("format") && _this5.config.formatCells !== false) {
  267. value = _this5.table.modules.format.formatExportValue(cellWrapper, _this5.colVisProp);
  268. } else {
  269. switch (typeof value === "undefined" ? "undefined" : _typeof(value)) {
  270. case "object":
  271. value = JSON.stringify(value);
  272. break;
  273. case "undefined":
  274. case "null":
  275. value = "";
  276. break;
  277. default:
  278. value = value;
  279. }
  280. }
  281. if (value instanceof Node) {
  282. cellEl.appendChild(value);
  283. } else {
  284. cellEl.innerHTML = value;
  285. }
  286. if (firstCell) {
  287. _this5.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"]);
  288. if (column.definition.align) {
  289. cellEl.style.textAlign = column.definition.align;
  290. }
  291. }
  292. if (_this5.table.options.dataTree && _this5.config.dataTree !== false) {
  293. if (treeElementField && treeElementField == column.field || !treeElementField && i == 0) {
  294. if (row.modules.dataTree.controlEl) {
  295. cellEl.insertBefore(row.modules.dataTree.controlEl.cloneNode(true), cellEl.firstChild);
  296. }
  297. if (row.modules.dataTree.branchEl) {
  298. cellEl.insertBefore(row.modules.dataTree.branchEl.cloneNode(true), cellEl.firstChild);
  299. }
  300. }
  301. }
  302. rowEl.appendChild(cellEl);
  303. if (cellWrapper.modules.format && cellWrapper.modules.format.renderedCallback) {
  304. cellWrapper.modules.format.renderedCallback();
  305. }
  306. });
  307. styleRow = row.type == "calc" ? calcRow : i % 2 && evenRow ? evenRow : oddRow;
  308. _this5.mapElementStyles(styleRow, rowEl, ["border-top", "border-left", "border-right", "border-bottom", "color", "font-weight", "font-family", "font-size", "background-color"]);
  309. if (rowFormatter && _this5.config.formatCells !== false) {
  310. var rowComponent = row.getComponent();
  311. rowComponent.getElement = function () {
  312. return rowEl;
  313. };
  314. rowFormatter(rowComponent);
  315. }
  316. break;
  317. }
  318. bodyEl.appendChild(rowEl);
  319. });
  320. return bodyEl;
  321. };
  322. Export.prototype.columnVisCheck = function (column) {
  323. return column.definition[this.colVisProp] !== false && (column.visible || !column.visible && column.definition[this.colVisProp]);
  324. };
  325. Export.prototype.getHtml = function (visible, style, config, colVisProp) {
  326. var holder = document.createElement("div");
  327. holder.appendChild(this.genereateTable(config || this.table.options.htmlOutputConfig, style, visible, colVisProp || "htmlOutput"));
  328. return holder.innerHTML;
  329. };
  330. Export.prototype.mapElementStyles = function (from, to, props) {
  331. if (this.cloneTableStyle && from && to) {
  332. var lookup = {
  333. "background-color": "backgroundColor",
  334. "color": "fontColor",
  335. "width": "width",
  336. "font-weight": "fontWeight",
  337. "font-family": "fontFamily",
  338. "font-size": "fontSize",
  339. "text-align": "textAlign",
  340. "border-top": "borderTop",
  341. "border-left": "borderLeft",
  342. "border-right": "borderRight",
  343. "border-bottom": "borderBottom",
  344. "padding-top": "paddingTop",
  345. "padding-left": "paddingLeft",
  346. "padding-right": "paddingRight",
  347. "padding-bottom": "paddingBottom"
  348. };
  349. if (window.getComputedStyle) {
  350. var fromStyle = window.getComputedStyle(from);
  351. props.forEach(function (prop) {
  352. to.style[lookup[prop]] = fromStyle.getPropertyValue(prop);
  353. });
  354. }
  355. }
  356. };
  357. Tabulator.prototype.registerModule("export", Export);