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

format.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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 Format = function Format(table) {
  4. this.table = table; //hold Tabulator object
  5. };
  6. //initialize column formatter
  7. Format.prototype.initializeColumn = function (column) {
  8. column.modules.format = this.lookupFormatter(column, "");
  9. if (typeof column.definition.formatterPrint !== "undefined") {
  10. column.modules.format.print = this.lookupFormatter(column, "Print");
  11. }
  12. if (typeof column.definition.formatterClipboard !== "undefined") {
  13. column.modules.format.clipboard = this.lookupFormatter(column, "Clipboard");
  14. }
  15. if (typeof column.definition.formatterHtmlOutput !== "undefined") {
  16. column.modules.format.htmlOutput = this.lookupFormatter(column, "HtmlOutput");
  17. }
  18. };
  19. Format.prototype.lookupFormatter = function (column, type) {
  20. var config = { params: column.definition["formatter" + type + "Params"] || {} },
  21. formatter = column.definition["formatter" + type];
  22. //set column formatter
  23. switch (typeof formatter === "undefined" ? "undefined" : _typeof(formatter)) {
  24. case "string":
  25. if (formatter === "tick") {
  26. formatter = "tickCross";
  27. if (typeof config.params.crossElement == "undefined") {
  28. config.params.crossElement = false;
  29. }
  30. console.warn("DEPRECATION WARNING - the tick formatter has been deprecated, please use the tickCross formatter with the crossElement param set to false");
  31. }
  32. if (this.formatters[formatter]) {
  33. config.formatter = this.formatters[formatter];
  34. } else {
  35. console.warn("Formatter Error - No such formatter found: ", formatter);
  36. config.formatter = this.formatters.plaintext;
  37. }
  38. break;
  39. case "function":
  40. config.formatter = formatter;
  41. break;
  42. default:
  43. config.formatter = this.formatters.plaintext;
  44. break;
  45. }
  46. return config;
  47. };
  48. Format.prototype.cellRendered = function (cell) {
  49. if (cell.modules.format && cell.modules.format.renderedCallback) {
  50. cell.modules.format.renderedCallback();
  51. }
  52. };
  53. //return a formatted value for a cell
  54. Format.prototype.formatValue = function (cell) {
  55. var component = cell.getComponent(),
  56. params = typeof cell.column.modules.format.params === "function" ? cell.column.modules.format.params(component) : cell.column.modules.format.params;
  57. function onRendered(callback) {
  58. if (!cell.modules.format) {
  59. cell.modules.format = {};
  60. }
  61. cell.modules.format.renderedCallback = callback;
  62. }
  63. return cell.column.modules.format.formatter.call(this, component, params, onRendered);
  64. };
  65. Format.prototype.formatExportValue = function (cell, type) {
  66. var formatter = cell.column.modules.format[type],
  67. params;
  68. if (formatter) {
  69. var onRendered = function onRendered(callback) {
  70. if (!cell.modules.format) {
  71. cell.modules.format = {};
  72. }
  73. cell.modules.format.renderedCallback = callback;
  74. };
  75. params = typeof formatter.params === "function" ? formatter.params(component) : formatter.params;
  76. return formatter.formatter.call(this, cell.getComponent(), params, onRendered);
  77. } else {
  78. return this.formatValue(cell);
  79. }
  80. };
  81. Format.prototype.sanitizeHTML = function (value) {
  82. if (value) {
  83. var entityMap = {
  84. '&': '&',
  85. '<': '&lt;',
  86. '>': '&gt;',
  87. '"': '&quot;',
  88. "'": '&#39;',
  89. '/': '&#x2F;',
  90. '`': '&#x60;',
  91. '=': '&#x3D;'
  92. };
  93. return String(value).replace(/[&<>"'`=\/]/g, function (s) {
  94. return entityMap[s];
  95. });
  96. } else {
  97. return value;
  98. }
  99. };
  100. Format.prototype.emptyToSpace = function (value) {
  101. return value === null || typeof value === "undefined" || value === "" ? "&nbsp;" : value;
  102. };
  103. //get formatter for cell
  104. Format.prototype.getFormatter = function (formatter) {
  105. var formatter;
  106. switch (typeof formatter === "undefined" ? "undefined" : _typeof(formatter)) {
  107. case "string":
  108. if (this.formatters[formatter]) {
  109. formatter = this.formatters[formatter];
  110. } else {
  111. console.warn("Formatter Error - No such formatter found: ", formatter);
  112. formatter = this.formatters.plaintext;
  113. }
  114. break;
  115. case "function":
  116. formatter = formatter;
  117. break;
  118. default:
  119. formatter = this.formatters.plaintext;
  120. break;
  121. }
  122. return formatter;
  123. };
  124. //default data formatters
  125. Format.prototype.formatters = {
  126. //plain text value
  127. plaintext: function plaintext(cell, formatterParams, onRendered) {
  128. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  129. },
  130. //html text value
  131. html: function html(cell, formatterParams, onRendered) {
  132. return cell.getValue();
  133. },
  134. //multiline text area
  135. textarea: function textarea(cell, formatterParams, onRendered) {
  136. cell.getElement().style.whiteSpace = "pre-wrap";
  137. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  138. },
  139. //currency formatting
  140. money: function money(cell, formatterParams, onRendered) {
  141. var floatVal = parseFloat(cell.getValue()),
  142. number,
  143. integer,
  144. decimal,
  145. rgx;
  146. var decimalSym = formatterParams.decimal || ".";
  147. var thousandSym = formatterParams.thousand || ",";
  148. var symbol = formatterParams.symbol || "";
  149. var after = !!formatterParams.symbolAfter;
  150. var precision = typeof formatterParams.precision !== "undefined" ? formatterParams.precision : 2;
  151. if (isNaN(floatVal)) {
  152. return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
  153. }
  154. number = precision !== false ? floatVal.toFixed(precision) : floatVal;
  155. number = String(number).split(".");
  156. integer = number[0];
  157. decimal = number.length > 1 ? decimalSym + number[1] : "";
  158. rgx = /(\d+)(\d{3})/;
  159. while (rgx.test(integer)) {
  160. integer = integer.replace(rgx, "$1" + thousandSym + "$2");
  161. }
  162. return after ? integer + decimal + symbol : symbol + integer + decimal;
  163. },
  164. //clickable anchor tag
  165. link: function link(cell, formatterParams, onRendered) {
  166. var value = cell.getValue(),
  167. urlPrefix = formatterParams.urlPrefix || "",
  168. download = formatterParams.download,
  169. label = value,
  170. el = document.createElement("a"),
  171. data;
  172. if (formatterParams.labelField) {
  173. data = cell.getData();
  174. label = data[formatterParams.labelField];
  175. }
  176. if (formatterParams.label) {
  177. switch (_typeof(formatterParams.label)) {
  178. case "string":
  179. label = formatterParams.label;
  180. break;
  181. case "function":
  182. label = formatterParams.label(cell);
  183. break;
  184. }
  185. }
  186. if (label) {
  187. if (formatterParams.urlField) {
  188. data = cell.getData();
  189. value = data[formatterParams.urlField];
  190. }
  191. if (formatterParams.url) {
  192. switch (_typeof(formatterParams.url)) {
  193. case "string":
  194. value = formatterParams.url;
  195. break;
  196. case "function":
  197. value = formatterParams.url(cell);
  198. break;
  199. }
  200. }
  201. el.setAttribute("href", urlPrefix + value);
  202. if (formatterParams.target) {
  203. el.setAttribute("target", formatterParams.target);
  204. }
  205. if (formatterParams.download) {
  206. if (typeof download == "function") {
  207. download = download(cell);
  208. } else {
  209. download = download === true ? "" : download;
  210. }
  211. el.setAttribute("download", download);
  212. }
  213. el.innerHTML = this.emptyToSpace(this.sanitizeHTML(label));
  214. return el;
  215. } else {
  216. return "&nbsp;";
  217. }
  218. },
  219. //image element
  220. image: function image(cell, formatterParams, onRendered) {
  221. var el = document.createElement("img");
  222. el.setAttribute("src", cell.getValue());
  223. switch (_typeof(formatterParams.height)) {
  224. case "number":
  225. el.style.height = formatterParams.height + "px";
  226. break;
  227. case "string":
  228. el.style.height = formatterParams.height;
  229. break;
  230. }
  231. switch (_typeof(formatterParams.width)) {
  232. case "number":
  233. el.style.width = formatterParams.width + "px";
  234. break;
  235. case "string":
  236. el.style.width = formatterParams.width;
  237. break;
  238. }
  239. el.addEventListener("load", function () {
  240. cell.getRow().normalizeHeight();
  241. });
  242. return el;
  243. },
  244. //tick or cross
  245. tickCross: function tickCross(cell, formatterParams, onRendered) {
  246. var value = cell.getValue(),
  247. element = cell.getElement(),
  248. empty = formatterParams.allowEmpty,
  249. truthy = formatterParams.allowTruthy,
  250. tick = typeof formatterParams.tickElement !== "undefined" ? formatterParams.tickElement : '<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#2DC214" clip-rule="evenodd" d="M21.652,3.211c-0.293-0.295-0.77-0.295-1.061,0L9.41,14.34 c-0.293,0.297-0.771,0.297-1.062,0L3.449,9.351C3.304,9.203,3.114,9.13,2.923,9.129C2.73,9.128,2.534,9.201,2.387,9.351 l-2.165,1.946C0.078,11.445,0,11.63,0,11.823c0,0.194,0.078,0.397,0.223,0.544l4.94,5.184c0.292,0.296,0.771,0.776,1.062,1.07 l2.124,2.141c0.292,0.293,0.769,0.293,1.062,0l14.366-14.34c0.293-0.294,0.293-0.777,0-1.071L21.652,3.211z" fill-rule="evenodd"/></svg>',
  251. cross = typeof formatterParams.crossElement !== "undefined" ? formatterParams.crossElement : '<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#CE1515" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272 c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0 l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269 c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73 L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"/></svg>';
  252. if (truthy && value || value === true || value === "true" || value === "True" || value === 1 || value === "1") {
  253. element.setAttribute("aria-checked", true);
  254. return tick || "";
  255. } else {
  256. if (empty && (value === "null" || value === "" || value === null || typeof value === "undefined")) {
  257. element.setAttribute("aria-checked", "mixed");
  258. return "";
  259. } else {
  260. element.setAttribute("aria-checked", false);
  261. return cross || "";
  262. }
  263. }
  264. },
  265. datetime: function datetime(cell, formatterParams, onRendered) {
  266. var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss";
  267. var outputFormat = formatterParams.outputFormat || "DD/MM/YYYY hh:mm:ss";
  268. var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
  269. var value = cell.getValue();
  270. var newDatetime = moment(value, inputFormat);
  271. if (newDatetime.isValid()) {
  272. return newDatetime.format(outputFormat);
  273. } else {
  274. if (invalid === true) {
  275. return value;
  276. } else if (typeof invalid === "function") {
  277. return invalid(value);
  278. } else {
  279. return invalid;
  280. }
  281. }
  282. },
  283. datetimediff: function datetime(cell, formatterParams, onRendered) {
  284. var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss";
  285. var invalid = typeof formatterParams.invalidPlaceholder !== "undefined" ? formatterParams.invalidPlaceholder : "";
  286. var suffix = typeof formatterParams.suffix !== "undefined" ? formatterParams.suffix : false;
  287. var unit = typeof formatterParams.unit !== "undefined" ? formatterParams.unit : undefined;
  288. var humanize = typeof formatterParams.humanize !== "undefined" ? formatterParams.humanize : false;
  289. var date = typeof formatterParams.date !== "undefined" ? formatterParams.date : moment();
  290. var value = cell.getValue();
  291. var newDatetime = moment(value, inputFormat);
  292. if (newDatetime.isValid()) {
  293. if (humanize) {
  294. return moment.duration(newDatetime.diff(date)).humanize(suffix);
  295. } else {
  296. return newDatetime.diff(date, unit) + (suffix ? " " + suffix : "");
  297. }
  298. } else {
  299. if (invalid === true) {
  300. return value;
  301. } else if (typeof invalid === "function") {
  302. return invalid(value);
  303. } else {
  304. return invalid;
  305. }
  306. }
  307. },
  308. //select
  309. lookup: function lookup(cell, formatterParams, onRendered) {
  310. var value = cell.getValue();
  311. if (typeof formatterParams[value] === "undefined") {
  312. console.warn('Missing display value for ' + value);
  313. return value;
  314. }
  315. return formatterParams[value];
  316. },
  317. //star rating
  318. star: function star(cell, formatterParams, onRendered) {
  319. var value = cell.getValue(),
  320. element = cell.getElement(),
  321. maxStars = formatterParams && formatterParams.stars ? formatterParams.stars : 5,
  322. stars = document.createElement("span"),
  323. star = document.createElementNS('http://www.w3.org/2000/svg', "svg"),
  324. starActive = '<polygon fill="#FFEA00" stroke="#C1AB60" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>',
  325. starInactive = '<polygon fill="#D2D2D2" stroke="#686868" stroke-width="37.6152" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" points="259.216,29.942 330.27,173.919 489.16,197.007 374.185,309.08 401.33,467.31 259.216,392.612 117.104,467.31 144.25,309.08 29.274,197.007 188.165,173.919 "/>';
  326. //style stars holder
  327. stars.style.verticalAlign = "middle";
  328. //style star
  329. star.setAttribute("width", "14");
  330. star.setAttribute("height", "14");
  331. star.setAttribute("viewBox", "0 0 512 512");
  332. star.setAttribute("xml:space", "preserve");
  333. star.style.padding = "0 1px";
  334. value = value && !isNaN(value) ? parseInt(value) : 0;
  335. value = Math.max(0, Math.min(value, maxStars));
  336. for (var i = 1; i <= maxStars; i++) {
  337. var nextStar = star.cloneNode(true);
  338. nextStar.innerHTML = i <= value ? starActive : starInactive;
  339. stars.appendChild(nextStar);
  340. }
  341. element.style.whiteSpace = "nowrap";
  342. element.style.overflow = "hidden";
  343. element.style.textOverflow = "ellipsis";
  344. element.setAttribute("aria-label", value);
  345. return stars;
  346. },
  347. traffic: function traffic(cell, formatterParams, onRendered) {
  348. var value = this.sanitizeHTML(cell.getValue()) || 0,
  349. el = document.createElement("span"),
  350. max = formatterParams && formatterParams.max ? formatterParams.max : 100,
  351. min = formatterParams && formatterParams.min ? formatterParams.min : 0,
  352. colors = formatterParams && typeof formatterParams.color !== "undefined" ? formatterParams.color : ["red", "orange", "green"],
  353. color = "#666666",
  354. percent,
  355. percentValue;
  356. if (isNaN(value) || typeof cell.getValue() === "undefined") {
  357. return;
  358. }
  359. el.classList.add("tabulator-traffic-light");
  360. //make sure value is in range
  361. percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
  362. percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
  363. //workout percentage
  364. percent = (max - min) / 100;
  365. percentValue = Math.round((percentValue - min) / percent);
  366. //set color
  367. switch (typeof colors === "undefined" ? "undefined" : _typeof(colors)) {
  368. case "string":
  369. color = colors;
  370. break;
  371. case "function":
  372. color = colors(value);
  373. break;
  374. case "object":
  375. if (Array.isArray(colors)) {
  376. var unit = 100 / colors.length;
  377. var index = Math.floor(percentValue / unit);
  378. index = Math.min(index, colors.length - 1);
  379. index = Math.max(index, 0);
  380. color = colors[index];
  381. break;
  382. }
  383. }
  384. el.style.backgroundColor = color;
  385. return el;
  386. },
  387. //progress bar
  388. progress: function progress(cell, formatterParams, onRendered) {
  389. //progress bar
  390. var value = this.sanitizeHTML(cell.getValue()) || 0,
  391. element = cell.getElement(),
  392. max = formatterParams && formatterParams.max ? formatterParams.max : 100,
  393. min = formatterParams && formatterParams.min ? formatterParams.min : 0,
  394. legendAlign = formatterParams && formatterParams.legendAlign ? formatterParams.legendAlign : "center",
  395. percent,
  396. percentValue,
  397. color,
  398. legend,
  399. legendColor,
  400. top,
  401. left,
  402. right,
  403. bottom;
  404. //make sure value is in range
  405. percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
  406. percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
  407. //workout percentage
  408. percent = (max - min) / 100;
  409. percentValue = Math.round((percentValue - min) / percent);
  410. //set bar color
  411. switch (_typeof(formatterParams.color)) {
  412. case "string":
  413. color = formatterParams.color;
  414. break;
  415. case "function":
  416. color = formatterParams.color(value);
  417. break;
  418. case "object":
  419. if (Array.isArray(formatterParams.color)) {
  420. var unit = 100 / formatterParams.color.length;
  421. var index = Math.floor(percentValue / unit);
  422. index = Math.min(index, formatterParams.color.length - 1);
  423. index = Math.max(index, 0);
  424. color = formatterParams.color[index];
  425. break;
  426. }
  427. default:
  428. color = "#2DC214";
  429. }
  430. //generate legend
  431. switch (_typeof(formatterParams.legend)) {
  432. case "string":
  433. legend = formatterParams.legend;
  434. break;
  435. case "function":
  436. legend = formatterParams.legend(value);
  437. break;
  438. case "boolean":
  439. legend = value;
  440. break;
  441. default:
  442. legend = false;
  443. }
  444. //set legend color
  445. switch (_typeof(formatterParams.legendColor)) {
  446. case "string":
  447. legendColor = formatterParams.legendColor;
  448. break;
  449. case "function":
  450. legendColor = formatterParams.legendColor(value);
  451. break;
  452. case "object":
  453. if (Array.isArray(formatterParams.legendColor)) {
  454. var unit = 100 / formatterParams.legendColor.length;
  455. var index = Math.floor(percentValue / unit);
  456. index = Math.min(index, formatterParams.legendColor.length - 1);
  457. index = Math.max(index, 0);
  458. legendColor = formatterParams.legendColor[index];
  459. }
  460. break;
  461. default:
  462. legendColor = "#000";
  463. }
  464. element.style.minWidth = "30px";
  465. element.style.position = "relative";
  466. element.setAttribute("aria-label", percentValue);
  467. var barEl = document.createElement("div");
  468. barEl.style.display = "inline-block";
  469. barEl.style.position = "relative";
  470. barEl.style.width = percentValue + "%";
  471. barEl.style.backgroundColor = color;
  472. barEl.style.height = "100%";
  473. barEl.setAttribute('data-max', max);
  474. barEl.setAttribute('data-min', min);
  475. if (legend) {
  476. var legendEl = document.createElement("div");
  477. legendEl.style.position = "absolute";
  478. legendEl.style.top = "4px";
  479. legendEl.style.left = 0;
  480. legendEl.style.textAlign = legendAlign;
  481. legendEl.style.width = "100%";
  482. legendEl.style.color = legendColor;
  483. legendEl.innerHTML = legend;
  484. }
  485. onRendered(function () {
  486. //handle custom element needed if formatter is to be included in printed/downloaded output
  487. if (!(cell instanceof CellComponent)) {
  488. var holderEl = document.createElement("div");
  489. holderEl.style.position = "absolute";
  490. holderEl.style.top = "4px";
  491. holderEl.style.bottom = "4px";
  492. holderEl.style.left = "4px";
  493. holderEl.style.right = "4px";
  494. element.appendChild(holderEl);
  495. element = holderEl;
  496. }
  497. element.appendChild(barEl);
  498. if (legend) {
  499. element.appendChild(legendEl);
  500. }
  501. });
  502. return "";
  503. },
  504. //background color
  505. color: function color(cell, formatterParams, onRendered) {
  506. cell.getElement().style.backgroundColor = this.sanitizeHTML(cell.getValue());
  507. return "";
  508. },
  509. //tick icon
  510. buttonTick: function buttonTick(cell, formatterParams, onRendered) {
  511. return '<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#2DC214" clip-rule="evenodd" d="M21.652,3.211c-0.293-0.295-0.77-0.295-1.061,0L9.41,14.34 c-0.293,0.297-0.771,0.297-1.062,0L3.449,9.351C3.304,9.203,3.114,9.13,2.923,9.129C2.73,9.128,2.534,9.201,2.387,9.351 l-2.165,1.946C0.078,11.445,0,11.63,0,11.823c0,0.194,0.078,0.397,0.223,0.544l4.94,5.184c0.292,0.296,0.771,0.776,1.062,1.07 l2.124,2.141c0.292,0.293,0.769,0.293,1.062,0l14.366-14.34c0.293-0.294,0.293-0.777,0-1.071L21.652,3.211z" fill-rule="evenodd"/></svg>';
  512. },
  513. //cross icon
  514. buttonCross: function buttonCross(cell, formatterParams, onRendered) {
  515. return '<svg enable-background="new 0 0 24 24" height="14" width="14" viewBox="0 0 24 24" xml:space="preserve" ><path fill="#CE1515" d="M22.245,4.015c0.313,0.313,0.313,0.826,0,1.139l-6.276,6.27c-0.313,0.312-0.313,0.826,0,1.14l6.273,6.272 c0.313,0.313,0.313,0.826,0,1.14l-2.285,2.277c-0.314,0.312-0.828,0.312-1.142,0l-6.271-6.271c-0.313-0.313-0.828-0.313-1.141,0 l-6.276,6.267c-0.313,0.313-0.828,0.313-1.141,0l-2.282-2.28c-0.313-0.313-0.313-0.826,0-1.14l6.278-6.269 c0.313-0.312,0.313-0.826,0-1.14L1.709,5.147c-0.314-0.313-0.314-0.827,0-1.14l2.284-2.278C4.308,1.417,4.821,1.417,5.135,1.73 L11.405,8c0.314,0.314,0.828,0.314,1.141,0.001l6.276-6.267c0.312-0.312,0.826-0.312,1.141,0L22.245,4.015z"/></svg>';
  516. },
  517. //current row number
  518. rownum: function rownum(cell, formatterParams, onRendered) {
  519. return this.table.rowManager.activeRows.indexOf(cell.getRow()._getSelf()) + 1;
  520. },
  521. //row handle
  522. handle: function handle(cell, formatterParams, onRendered) {
  523. cell.getElement().classList.add("tabulator-row-handle");
  524. return "<div class='tabulator-row-handle-box'><div class='tabulator-row-handle-bar'></div><div class='tabulator-row-handle-bar'></div><div class='tabulator-row-handle-bar'></div></div>";
  525. },
  526. responsiveCollapse: function responsiveCollapse(cell, formatterParams, onRendered) {
  527. var self = this,
  528. open = false,
  529. el = document.createElement("div"),
  530. config = cell.getRow()._row.modules.responsiveLayout;
  531. el.classList.add("tabulator-responsive-collapse-toggle");
  532. el.innerHTML = "<span class='tabulator-responsive-collapse-toggle-open'>+</span><span class='tabulator-responsive-collapse-toggle-close'>-</span>";
  533. cell.getElement().classList.add("tabulator-row-handle");
  534. function toggleList(isOpen) {
  535. var collapseEl = config.element;
  536. config.open = isOpen;
  537. if (collapseEl) {
  538. if (config.open) {
  539. el.classList.add("open");
  540. collapseEl.style.display = '';
  541. } else {
  542. el.classList.remove("open");
  543. collapseEl.style.display = 'none';
  544. }
  545. }
  546. }
  547. el.addEventListener("click", function (e) {
  548. e.stopImmediatePropagation();
  549. toggleList(!config.open);
  550. });
  551. toggleList(config.open);
  552. return el;
  553. },
  554. rowSelection: function rowSelection(cell) {
  555. var _this = this;
  556. var checkbox = document.createElement("input");
  557. checkbox.type = 'checkbox';
  558. if (this.table.modExists("selectRow", true)) {
  559. checkbox.addEventListener("click", function (e) {
  560. e.stopPropagation();
  561. });
  562. if (typeof cell.getRow == 'function') {
  563. var row = cell.getRow();
  564. checkbox.addEventListener("change", function (e) {
  565. row.toggleSelect();
  566. });
  567. checkbox.checked = row.isSelected();
  568. this.table.modules.selectRow.registerRowSelectCheckbox(row, checkbox);
  569. } else {
  570. checkbox.addEventListener("change", function (e) {
  571. if (_this.table.modules.selectRow.selectedRows.length) {
  572. _this.table.deselectRow();
  573. } else {
  574. _this.table.selectRow();
  575. }
  576. });
  577. this.table.modules.selectRow.registerHeaderSelectCheckbox(checkbox);
  578. }
  579. }
  580. return checkbox;
  581. }
  582. };
  583. Tabulator.prototype.registerModule("format", Format);