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 Format =
function Format(table) {
10 Format.prototype.initializeColumn =
function (column) {
12 config = { params: column.definition.formatterParams || {} };
15 switch (_typeof(column.definition.formatter)) {
18 if (column.definition.formatter ===
"tick") {
19 column.definition.formatter =
"tickCross";
21 if (typeof config.params.crossElement ==
"undefined") {
22 config.params.crossElement =
false;
25 console.warn(
"DEPRECATION WARNING - the tick formatter has been deprecated, please use the tickCross formatter with the crossElement param set to false");
28 if (
self.formatters[column.definition.formatter]) {
29 config.formatter =
self.formatters[column.definition.formatter];
31 console.warn(
"Formatter Error - No such formatter found: ", column.definition.formatter);
32 config.formatter =
self.formatters.plaintext;
37 config.formatter = column.definition.formatter;
41 config.formatter =
self.formatters.plaintext;
45 column.modules.format = config;
48 Format.prototype.cellRendered =
function (cell) {
49 if (cell.modules.format && cell.modules.format.renderedCallback) {
50 cell.modules.format.renderedCallback();
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;
59 function onRendered(callback) {
60 if (!cell.modules.format) {
61 cell.modules.format = {};
64 cell.modules.format.renderedCallback = callback;
67 return cell.column.modules.format.formatter.call(
this, component, params, onRendered);
70 Format.prototype.sanitizeHTML =
function (value) {
83 return String(value).replace(/[&<>
"'`=\/]/g, function (s) {
91 Format.prototype.emptyToSpace = function (value) {
92 return value === null || typeof value === "undefined
" ? "
" : value;
95 //get formatter for cell
96 Format.prototype.getFormatter = function (formatter) {
99 switch (typeof formatter === "undefined
" ? "undefined
" : _typeof(formatter)) {
101 if (this.formatters[formatter]) {
102 formatter = this.formatters[formatter];
104 console.warn("Formatter Error - No such formatter found:
", formatter);
105 formatter = this.formatters.plaintext;
110 formatter = formatter;
114 formatter = this.formatters.plaintext;
121 //default data formatters
122 Format.prototype.formatters = {
124 plaintext: function plaintext(cell, formatterParams, onRendered) {
125 return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
129 html: function html(cell, formatterParams, onRendered) {
130 return cell.getValue();
133 //multiline text area
134 textarea: function textarea(cell, formatterParams, onRendered) {
135 cell.getElement().style.whiteSpace = "pre-wrap
";
136 return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
139 //currency formatting
140 money: function money(cell, formatterParams, onRendered) {
141 var floatVal = parseFloat(cell.getValue()),
147 var decimalSym = formatterParams.decimal || ".
";
148 var thousandSym = formatterParams.thousand || ",
";
149 var symbol = formatterParams.symbol || "";
150 var after = !!formatterParams.symbolAfter;
151 var precision = typeof formatterParams.precision !== "undefined
" ? formatterParams.precision : 2;
153 if (isNaN(floatVal)) {
154 return this.emptyToSpace(this.sanitizeHTML(cell.getValue()));
157 number = precision !== false ? floatVal.toFixed(precision) : floatVal;
158 number = String(number).split(".
");
161 decimal = number.length > 1 ? decimalSym + number[1] : "";
163 rgx = /(\d+)(\d{3})/;
165 while (rgx.test(integer)) {
166 integer = integer.replace(rgx, "$1
" + thousandSym + "$2
");
169 return after ? integer + decimal + symbol : symbol + integer + decimal;
172 //clickable anchor tag
173 link: function link(cell, formatterParams, onRendered) {
174 var value = cell.getValue(),
175 urlPrefix = formatterParams.urlPrefix || "",
176 download = formatterParams.download,
178 el = document.createElement("a
"),
181 if (formatterParams.labelField) {
182 data = cell.getData();
183 label = data[formatterParams.labelField];
186 if (formatterParams.label) {
187 switch (_typeof(formatterParams.label)) {
189 label = formatterParams.label;
193 label = formatterParams.label(cell);
199 if (formatterParams.urlField) {
200 data = cell.getData();
201 value = data[formatterParams.urlField];
204 if (formatterParams.url) {
205 switch (_typeof(formatterParams.url)) {
207 value = formatterParams.url;
211 value = formatterParams.url(cell);
216 el.setAttribute("href
", urlPrefix + value);
218 if (formatterParams.target) {
219 el.setAttribute("target
", formatterParams.target);
222 if (formatterParams.download) {
224 if (typeof download == "function") {
225 download = download(cell);
227 download = download === true ? "" : download;
230 el.setAttribute("download
", download);
233 el.innerHTML = this.emptyToSpace(this.sanitizeHTML(label));
242 image: function image(cell, formatterParams, onRendered) {
243 var el = document.createElement("img
");
244 el.setAttribute("src
", cell.getValue());
246 switch (_typeof(formatterParams.height)) {
248 el.style.height = formatterParams.height + "px
";
252 el.style.height = formatterParams.height;
256 switch (_typeof(formatterParams.width)) {
258 el.style.width = formatterParams.width + "px
";
262 el.style.width = formatterParams.width;
266 el.addEventListener("load
", function () {
267 cell.getRow().normalizeHeight();
274 tickCross: function tickCross(cell, formatterParams, onRendered) {
275 var value = cell.getValue(),
276 element = cell.getElement(),
277 empty = formatterParams.allowEmpty,
278 truthy = formatterParams.allowTruthy,
279 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>',
280 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>';
282 if (truthy && value || value === true || value === "true" || value === "True
" || value === 1 || value === "1
") {
283 element.setAttribute("aria-checked
", true);
286 if (empty && (value === "null
" || value === "" || value === null || typeof value === "undefined
")) {
287 element.setAttribute("aria-checked
", "mixed
");
290 element.setAttribute("aria-checked
", false);
296 datetime: function datetime(cell, formatterParams, onRendered) {
297 var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss
";
298 var outputFormat = formatterParams.outputFormat || "DD/MM/YYYY hh:mm:ss
";
299 var invalid = typeof formatterParams.invalidPlaceholder !== "undefined
" ? formatterParams.invalidPlaceholder : "";
300 var value = cell.getValue();
302 var newDatetime = moment(value, inputFormat);
304 if (newDatetime.isValid()) {
305 return newDatetime.format(outputFormat);
308 if (invalid === true) {
310 } else if (typeof invalid === "function") {
311 return invalid(value);
318 datetimediff: function datetime(cell, formatterParams, onRendered) {
319 var inputFormat = formatterParams.inputFormat || "YYYY-MM-DD hh:mm:ss
";
320 var invalid = typeof formatterParams.invalidPlaceholder !== "undefined
" ? formatterParams.invalidPlaceholder : "";
321 var suffix = typeof formatterParams.suffix !== "undefined
" ? formatterParams.suffix : false;
322 var unit = typeof formatterParams.unit !== "undefined
" ? formatterParams.unit : undefined;
323 var humanize = typeof formatterParams.humanize !== "undefined
" ? formatterParams.humanize : false;
324 var date = typeof formatterParams.date !== "undefined
" ? formatterParams.date : moment();
325 var value = cell.getValue();
327 var newDatetime = moment(value, inputFormat);
329 if (newDatetime.isValid()) {
331 return moment.duration(newDatetime.diff(date)).humanize(suffix);
333 return newDatetime.diff(date, unit) + (suffix ? " " + suffix : "");
337 if (invalid === true) {
339 } else if (typeof invalid === "function") {
340 return invalid(value);
348 lookup: function lookup(cell, formatterParams, onRendered) {
349 var value = cell.getValue();
351 if (typeof formatterParams[value] === "undefined
") {
352 console.warn('Missing display value for ' + value);
356 return formatterParams[value];
360 star: function star(cell, formatterParams, onRendered) {
361 var value = cell.getValue(),
362 element = cell.getElement(),
363 maxStars = formatterParams && formatterParams.stars ? formatterParams.stars : 5,
364 stars = document.createElement("span
"),
365 star = document.createElementNS('http://www.w3.org/2000/svg', "svg
"),
366 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
"/>',
367 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
"/>';
370 stars.style.verticalAlign = "middle
";
373 star.setAttribute("width
", "14
");
374 star.setAttribute("height
", "14
");
375 star.setAttribute("viewBox
", "0 0 512 512
");
376 star.setAttribute("xml:space
", "preserve
");
377 star.style.padding = "0 1px
";
379 value = value && !isNaN(value) ? parseInt(value) : 0;
381 value = Math.max(0, Math.min(value, maxStars));
383 for (var i = 1; i <= maxStars; i++) {
384 var nextStar = star.cloneNode(true);
385 nextStar.innerHTML = i <= value ? starActive : starInactive;
387 stars.appendChild(nextStar);
390 element.style.whiteSpace = "nowrap
";
391 element.style.overflow = "hidden
";
392 element.style.textOverflow = "ellipsis
";
394 element.setAttribute("aria-label
", value);
399 traffic: function traffic(cell, formatterParams, onRendered) {
400 var value = this.sanitizeHTML(cell.getValue()) || 0,
401 el = document.createElement("span
"),
402 max = formatterParams && formatterParams.max ? formatterParams.max : 100,
403 min = formatterParams && formatterParams.min ? formatterParams.min : 0,
404 colors = formatterParams && typeof formatterParams.color !== "undefined
" ? formatterParams.color : ["red
", "orange
", "green
"],
409 if (isNaN(value) || typeof cell.getValue() === "undefined
") {
413 el.classList.add("tabulator-traffic-light
");
415 //make sure value is in range
416 percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
417 percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
420 percent = (max - min) / 100;
421 percentValue = Math.round((percentValue - min) / percent);
424 switch (typeof colors === "undefined
" ? "undefined
" : _typeof(colors)) {
429 color = colors(value);
432 if (Array.isArray(colors)) {
433 var unit = 100 / colors.length;
434 var index = Math.floor(percentValue / unit);
436 index = Math.min(index, colors.length - 1);
437 index = Math.max(index, 0);
438 color = colors[index];
443 el.style.backgroundColor = color;
449 progress: function progress(cell, formatterParams, onRendered) {
451 var value = this.sanitizeHTML(cell.getValue()) || 0,
452 element = cell.getElement(),
453 max = formatterParams && formatterParams.max ? formatterParams.max : 100,
454 min = formatterParams && formatterParams.min ? formatterParams.min : 0,
455 legendAlign = formatterParams && formatterParams.legendAlign ? formatterParams.legendAlign : "center
",
466 //make sure value is in range
467 percentValue = parseFloat(value) <= max ? parseFloat(value) : max;
468 percentValue = parseFloat(percentValue) >= min ? parseFloat(percentValue) : min;
471 percent = (max - min) / 100;
472 percentValue = Math.round((percentValue - min) / percent);
475 switch (_typeof(formatterParams.color)) {
477 color = formatterParams.color;
480 color = formatterParams.color(value);
483 if (Array.isArray(formatterParams.color)) {
484 var unit = 100 / formatterParams.color.length;
485 var index = Math.floor(percentValue / unit);
487 index = Math.min(index, formatterParams.color.length - 1);
488 index = Math.max(index, 0);
489 color = formatterParams.color[index];
497 switch (_typeof(formatterParams.legend)) {
499 legend = formatterParams.legend;
502 legend = formatterParams.legend(value);
512 switch (_typeof(formatterParams.legendColor)) {
514 legendColor = formatterParams.legendColor;
517 legendColor = formatterParams.legendColor(value);
520 if (Array.isArray(formatterParams.legendColor)) {
521 var unit = 100 / formatterParams.legendColor.length;
522 var index = Math.floor(percentValue / unit);
524 index = Math.min(index, formatterParams.legendColor.length - 1);
525 index = Math.max(index, 0);
526 legendColor = formatterParams.legendColor[index];
530 legendColor = "#000
";
533 element.style.minWidth = "30px
";
534 element.style.position = "relative
";
536 element.setAttribute("aria-label
", percentValue);
538 var barEl = document.createElement("div
");
539 barEl.style.display = "inline-block
";
540 barEl.style.position = "relative
";
541 barEl.style.width = percentValue + "%
";
542 barEl.style.backgroundColor = color;
543 barEl.style.height = "100%
";
545 barEl.setAttribute('data-max', max);
546 barEl.setAttribute('data-min', min);
549 var legendEl = document.createElement("div
");
550 legendEl.style.position = "absolute
";
551 legendEl.style.top = "4px
";
552 legendEl.style.left = 0;
553 legendEl.style.textAlign = legendAlign;
554 legendEl.style.width = "100%
";
555 legendEl.style.color = legendColor;
556 legendEl.innerHTML = legend;
559 onRendered(function () {
560 element.appendChild(barEl);
563 element.appendChild(legendEl);
571 color: function color(cell, formatterParams, onRendered) {
572 cell.getElement().style.backgroundColor = this.sanitizeHTML(cell.getValue());
577 buttonTick: function buttonTick(cell, formatterParams, onRendered) {
578 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>';
582 buttonCross: function buttonCross(cell, formatterParams, onRendered) {
583 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>';
587 rownum: function rownum(cell, formatterParams, onRendered) {
588 return this.table.rowManager.activeRows.indexOf(cell.getRow()._getSelf()) + 1;
592 handle: function handle(cell, formatterParams, onRendered) {
593 cell.getElement().classList.add("tabulator-row-handle
");
594 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>
";
597 responsiveCollapse: function responsiveCollapse(cell, formatterParams, onRendered) {
600 el = document.createElement("div
"),
601 config = cell.getRow()._row.modules.responsiveLayout;
603 el.classList.add("tabulator-responsive-collapse-toggle
");
604 el.innerHTML = "<span
class=
'tabulator-responsive-collapse-toggle-open'>+</span><span
class=
'tabulator-responsive-collapse-toggle-close'>-</span>
";
606 cell.getElement().classList.add("tabulator-row-handle
");
608 function toggleList(isOpen) {
609 var collapseEl = config.element;
611 config.open = isOpen;
616 el.classList.add("open
");
617 collapseEl.style.display = '';
619 el.classList.remove("open
");
620 collapseEl.style.display = 'none';
625 el.addEventListener("click
", function (e) {
626 e.stopImmediatePropagation();
627 toggleList(!config.open);
630 toggleList(config.open);
635 rowSelection: function rowSelection(cell) {
638 var checkbox = document.createElement("input
");
640 checkbox.type = 'checkbox';
642 if (this.table.modExists("selectRow
", true)) {
644 checkbox.addEventListener("click
", function (e) {
648 if (typeof cell.getRow == 'function') {
649 var row = cell.getRow();
651 checkbox.addEventListener("change
", function (e) {
655 checkbox.checked = row.isSelected();
656 this.table.modules.selectRow.registerRowSelectCheckbox(row, checkbox);
658 checkbox.addEventListener("change
", function (e) {
659 if (_this.table.modules.selectRow.selectedRows.length) {
660 _this.table.deselectRow();
662 _this.table.selectRow();
666 this.table.modules.selectRow.registerHeaderSelectCheckbox(checkbox);
673 Tabulator.prototype.registerModule("format
", Format);