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

format.js 23KB

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