"));
- }
+ var tr = Utils.h('tr', _objectSpread2(_objectSpread2({}, attributes), {}, {
+ id: Array.isArray(item) ? undefined : item._id,
+ class: style && style.classes || (Array.isArray(item) ? undefined : item._class),
+ style: style && style.css || (Array.isArray(item) ? undefined : item._style),
+ 'data-index': i,
+ 'data-uniqueid': Utils.getItemField(item, this.options.uniqueId, false),
+ 'data-has-detail-view': this.options.detailView && Utils.calculateObjectValue(null, this.options.detailFilter, [i, item]) ? 'true' : undefined
+ }, data_));
+ var trChildren = [];
var detailViewTemplate = '';
if (Utils.hasDetailViewIcon(this.options)) {
- detailViewTemplate = '
';
+ detailViewTemplate = Utils.h('td');
if (Utils.calculateObjectValue(null, this.options.detailFilter, [i, item])) {
- detailViewTemplate += "\n \n ".concat(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen), "\n \n ");
+ detailViewTemplate.append(Utils.h('a', {
+ class: 'detail-icon',
+ href: '#',
+ html: Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen)
+ }));
}
- detailViewTemplate += ' | ';
}
if (detailViewTemplate && this.options.detailViewAlign !== 'right') {
- html.push(detailViewTemplate);
+ trChildren.push(detailViewTemplate);
}
- this.header.fields.forEach(function (field, j) {
+ var tds = this.header.fields.map(function (field, j) {
var column = _this7.columns[j];
- var text = '';
var value_ = Utils.getItemField(item, field, _this7.options.escape, column.escape);
var value = '';
- var type = '';
- var cellStyle = {};
- var id_ = '';
- var class_ = _this7.header.classes[j];
- var style_ = '';
- var styleToAdd_ = '';
- var data_ = '';
- var rowspan_ = '';
- var colspan_ = '';
- var title_ = '';
+ var attrs = {
+ class: _this7.header.classes[j] ? [_this7.header.classes[j]] : [],
+ style: _this7.header.styles[j] ? [_this7.header.styles[j]] : []
+ };
if ((_this7.fromHtml || _this7.autoMergeCells) && typeof value_ === 'undefined') {
if (!column.checkbox && !column.radio) {
return;
@@ -7252,47 +9729,25 @@
return;
}
- // Style concat
- if (csses.concat([_this7.header.styles[j]]).length) {
- styleToAdd_ += "".concat(csses.concat([_this7.header.styles[j]]).join('; '));
+ // handle class, style, id, rowspan, colspan and title of td
+ for (var _i10 = 0, _arr = ['class', 'style', 'id', 'rowspan', 'colspan', 'title']; _i10 < _arr.length; _i10++) {
+ var _item = _arr[_i10];
+ var _value = _item["_".concat(field, "_").concat(_item)];
+ if (!_value) {
+ continue;
+ }
+ if (attrs[_item]) {
+ attrs[_item].push(_value);
+ } else {
+ attrs[_item] = _value;
+ }
}
- if (item["_".concat(field, "_style")]) {
- styleToAdd_ += "".concat(item["_".concat(field, "_style")]);
- }
- if (styleToAdd_) {
- style_ = " style=\"".concat(styleToAdd_, "\"");
- }
- // Style concat
-
- // handle id and class of td
- if (item["_".concat(field, "_id")]) {
- id_ = Utils.sprintf(' id="%s"', item["_".concat(field, "_id")]);
- }
- if (item["_".concat(field, "_class")]) {
- class_ = Utils.sprintf(' class="%s"', item["_".concat(field, "_class")]);
- }
- if (item["_".concat(field, "_rowspan")]) {
- rowspan_ = Utils.sprintf(' rowspan="%s"', item["_".concat(field, "_rowspan")]);
- }
- if (item["_".concat(field, "_colspan")]) {
- colspan_ = Utils.sprintf(' colspan="%s"', item["_".concat(field, "_colspan")]);
- }
- if (item["_".concat(field, "_title")]) {
- title_ = Utils.sprintf(' title="%s"', item["_".concat(field, "_title")]);
- }
- cellStyle = Utils.calculateObjectValue(_this7.header, _this7.header.cellStyles[j], [value_, item, i, field], cellStyle);
+ var cellStyle = Utils.calculateObjectValue(_this7.header, _this7.header.cellStyles[j], [value_, item, i, field], {});
if (cellStyle.classes) {
- class_ = " class=\"".concat(cellStyle.classes, "\"");
+ attrs.class.push(cellStyle.classes);
}
if (cellStyle.css) {
- var csses_ = [];
- for (var _i12 = 0, _Object$entries11 = Object.entries(cellStyle.css); _i12 < _Object$entries11.length; _i12++) {
- var _Object$entries11$_i = _slicedToArray(_Object$entries11[_i12], 2),
- _key3 = _Object$entries11$_i[0],
- _value2 = _Object$entries11$_i[1];
- csses_.push("".concat(_key3, ": ").concat(_value2));
- }
- style_ = " style=\"".concat(csses_.concat(_this7.header.styles[j]).join('; '), "\"");
+ attrs.style.push(cellStyle.css);
}
value = Utils.calculateObjectValue(column, _this7.header.formatters[j], [value_, item, i, field], value_);
if (!(column.checkbox || column.radio)) {
@@ -7300,7 +9755,7 @@
}
if (column.searchable && _this7.searchText && _this7.options.searchHighlight && !(column.checkbox || column.radio)) {
var searchText = _this7.searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
- if (_this7.options.searchAccentNeutralise) {
+ if (_this7.options.searchAccentNeutralise && typeof value === 'string') {
var indexRegex = new RegExp("".concat(Utils.normalizeAccent(searchText)), 'gmi');
var match = indexRegex.exec(Utils.normalizeAccent(value));
if (match) {
@@ -7311,44 +9766,71 @@
value = Utils.calculateObjectValue(column, column.searchHighlightFormatter, [value, _this7.searchText], defValue);
}
if (item["_".concat(field, "_data")] && !Utils.isEmptyObject(item["_".concat(field, "_data")])) {
- for (var _i13 = 0, _Object$entries12 = Object.entries(item["_".concat(field, "_data")]); _i13 < _Object$entries12.length; _i13++) {
- var _Object$entries12$_i = _slicedToArray(_Object$entries12[_i13], 2),
- _k = _Object$entries12$_i[0],
- _v = _Object$entries12$_i[1];
+ for (var _i11 = 0, _Object$entries9 = Object.entries(item["_".concat(field, "_data")]); _i11 < _Object$entries9.length; _i11++) {
+ var _Object$entries9$_i = _slicedToArray(_Object$entries9[_i11], 2),
+ _k = _Object$entries9$_i[0],
+ _v = _Object$entries9$_i[1];
// ignore data-index
if (_k === 'index') {
return;
}
- data_ += " data-".concat(_k, "=\"").concat(_v, "\"");
+ attrs["data-".concat(_k)] = _v;
}
}
if (column.checkbox || column.radio) {
- type = column.checkbox ? 'checkbox' : type;
- type = column.radio ? 'radio' : type;
- var c = column['class'] || '';
+ var type = column.checkbox ? 'checkbox' : 'radio';
var isChecked = Utils.isObject(value) && value.hasOwnProperty('checked') ? value.checked : (value === true || value_) && value !== false;
var isDisabled = !column.checkboxEnabled || value && value.disabled;
- text = [_this7.options.cardView ? "
") : "
"), ""), _this7.header.formatters[j] && typeof value === 'string' ? value : '', _this7.options.cardView ? '' : ' | '].join('');
+ var valueNodes = _this7.header.formatters[j] && (typeof value === 'string' || value instanceof Node || value instanceof $) ? Utils.htmlToNodes(value) : [];
item[_this7.header.stateField] = value === true || !!value_ || value && value.checked;
- } else if (_this7.options.cardView) {
- var cardTitle = _this7.options.showHeader ? "
").concat(Utils.getFieldTitle(_this7.columns, field), "") : '';
- text = "
".concat(cardTitle, "").concat(value, "
");
- if (_this7.options.smartDisplay && value === '') {
- text = '
';
- }
- } else {
- text = "
").concat(value, " | ");
+ return Utils.h(_this7.options.cardView ? 'div' : 'td', {
+ class: [_this7.options.cardView ? 'card-view' : 'bs-checkbox', column.class],
+ style: _this7.options.cardView ? undefined : attrs.style
+ }, [Utils.h('label', {}, [Utils.h('input', {
+ 'data-index': i,
+ name: _this7.options.selectItemName,
+ type: type,
+ value: item[_this7.options.idField],
+ checked: isChecked ? 'checked' : undefined,
+ disabled: isDisabled ? 'disabled' : undefined
+ }), Utils.h('span')])].concat(_toConsumableArray(valueNodes)));
}
- html.push(text);
+ if (_this7.options.cardView) {
+ if (_this7.options.smartDisplay && value === '') {
+ return Utils.h('div', {
+ class: 'card-view'
+ });
+ }
+ var cardTitle = _this7.options.showHeader ? Utils.h('span', {
+ class: ['card-view-title', cellStyle.classes],
+ style: attrs.style,
+ html: Utils.getFieldTitle(_this7.columns, field)
+ }) : '';
+ return Utils.h('div', {
+ class: 'card-view'
+ }, [cardTitle, Utils.h('span', {
+ class: ['card-view-value', cellStyle.classes],
+ style: attrs.style
+ }, _toConsumableArray(Utils.htmlToNodes(value)))]);
+ }
+ return Utils.h('td', attrs, _toConsumableArray(Utils.htmlToNodes(value)));
+ }).filter(function (x) {
+ return x;
});
+ trChildren.push.apply(trChildren, _toConsumableArray(tds));
if (detailViewTemplate && this.options.detailViewAlign === 'right') {
- html.push(detailViewTemplate);
+ trChildren.push(detailViewTemplate);
}
if (this.options.cardView) {
- html.push('