|
@@ -1596,57 +1596,131 @@
|
|
|
this.updatePagination(event);
|
|
this.updatePagination(event);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- BootstrapTable.prototype.initBody = function (fixedScroll) {
|
|
|
|
|
- var that = this,
|
|
|
|
|
|
|
+ BootstrapTable.prototype.initRow = function(item, i, data, parentDom) {
|
|
|
|
|
+ var that=this,
|
|
|
|
|
+ key,
|
|
|
html = [],
|
|
html = [],
|
|
|
- data = this.getData();
|
|
|
|
|
|
|
+ style = {},
|
|
|
|
|
+ csses = [],
|
|
|
|
|
+ data_ = '',
|
|
|
|
|
+ attributes = {},
|
|
|
|
|
+ htmlAttributes = [];
|
|
|
|
|
|
|
|
- this.trigger('pre-body', data);
|
|
|
|
|
|
|
+ if ($.inArray(item, this.hiddenRows) > -1) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- this.$body = this.$el.find('>tbody');
|
|
|
|
|
- if (!this.$body.length) {
|
|
|
|
|
- this.$body = $('<tbody></tbody>').appendTo(this.$el);
|
|
|
|
|
|
|
+ style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
|
|
|
|
|
+
|
|
|
|
|
+ if (style && style.css) {
|
|
|
|
|
+ for (key in style.css) {
|
|
|
|
|
+ csses.push(key + ': ' + style.css[key]);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- //Fix #389 Bootstrap-table-flatJSON is not working
|
|
|
|
|
|
|
+ attributes = calculateObjectValue(this.options,
|
|
|
|
|
+ this.options.rowAttributes, [item, i], attributes);
|
|
|
|
|
|
|
|
- if (!this.options.pagination || this.options.sidePagination === 'server') {
|
|
|
|
|
- this.pageFrom = 1;
|
|
|
|
|
- this.pageTo = data.length;
|
|
|
|
|
|
|
+ if (attributes) {
|
|
|
|
|
+ for (key in attributes) {
|
|
|
|
|
+ htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
|
|
|
|
|
- var key,
|
|
|
|
|
- item = data[i],
|
|
|
|
|
- style = {},
|
|
|
|
|
- csses = [],
|
|
|
|
|
|
|
+ if (item._data && !$.isEmptyObject(item._data)) {
|
|
|
|
|
+ $.each(item._data, function(k, v) {
|
|
|
|
|
+ // ignore data-index
|
|
|
|
|
+ if (k === 'index') {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ data_ += sprintf(' data-%s="%s"', k, v);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ html.push('<tr',
|
|
|
|
|
+ sprintf(' %s', htmlAttributes.join(' ')),
|
|
|
|
|
+ sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
|
|
|
|
|
+ sprintf(' class="%s"', style.classes || ($.isArray(item) ? undefined : item._class)),
|
|
|
|
|
+ sprintf(' data-index="%s"', i),
|
|
|
|
|
+ sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]),
|
|
|
|
|
+ sprintf('%s', data_),
|
|
|
|
|
+ '>'
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (this.options.cardView) {
|
|
|
|
|
+ html.push(sprintf('<td colspan="%s"><div class="card-views">', this.header.fields.length));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!this.options.cardView && this.options.detailView) {
|
|
|
|
|
+ html.push('<td>',
|
|
|
|
|
+ '<a class="detail-icon" href="javascript:">',
|
|
|
|
|
+ sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
|
|
|
|
|
+ '</a>',
|
|
|
|
|
+ '</td>');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $.each(this.header.fields, function(j, field) {
|
|
|
|
|
+ var text = '',
|
|
|
|
|
+ value_ = getItemField(item, field, that.options.escape),
|
|
|
|
|
+ value = '',
|
|
|
|
|
+ type = '',
|
|
|
|
|
+ cellStyle = {},
|
|
|
|
|
+ id_ = '',
|
|
|
|
|
+ class_ = that.header.classes[j],
|
|
|
data_ = '',
|
|
data_ = '',
|
|
|
- attributes = {},
|
|
|
|
|
- htmlAttributes = [];
|
|
|
|
|
|
|
+ rowspan_ = '',
|
|
|
|
|
+ colspan_ = '',
|
|
|
|
|
+ title_ = '',
|
|
|
|
|
+ column = that.columns[j];
|
|
|
|
|
|
|
|
- if ($.inArray(item, this.hiddenRows) > -1) {
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ if (that.fromHtml && typeof value_ === 'undefined') {
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
|
|
|
|
|
|
|
+ if (!column.visible) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (style && style.css) {
|
|
|
|
|
- for (key in style.css) {
|
|
|
|
|
- csses.push(key + ': ' + style.css[key]);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (that.options.cardView && (!column.cardVisible)) {
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- attributes = calculateObjectValue(this.options,
|
|
|
|
|
- this.options.rowAttributes, [item, i], attributes);
|
|
|
|
|
|
|
+ style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
|
|
|
|
|
|
|
|
- if (attributes) {
|
|
|
|
|
- for (key in attributes) {
|
|
|
|
|
- htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
|
|
|
|
|
|
|
+ // handle td's id and class
|
|
|
|
|
+ if (item['_' + field + '_id']) {
|
|
|
|
|
+ id_ = sprintf(' id="%s"', item['_' + field + '_id']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (item['_' + field + '_class']) {
|
|
|
|
|
+ class_ = sprintf(' class="%s"', item['_' + field + '_class']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (item['_' + field + '_rowspan']) {
|
|
|
|
|
+ rowspan_ = sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (item['_' + field + '_colspan']) {
|
|
|
|
|
+ colspan_ = sprintf(' colspan="%s"', item['_' + field + '_colspan']);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (item['_' + field + '_title']) {
|
|
|
|
|
+ title_ = sprintf(' title="%s"', item['_' + field + '_title']);
|
|
|
|
|
+ }
|
|
|
|
|
+ cellStyle = calculateObjectValue(that.header,
|
|
|
|
|
+ that.header.cellStyles[j], [value_, item, i, field], cellStyle);
|
|
|
|
|
+ if (cellStyle.classes) {
|
|
|
|
|
+ class_ = sprintf(' class="%s"', cellStyle.classes);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (cellStyle.css) {
|
|
|
|
|
+ var csses_ = [];
|
|
|
|
|
+ for (var key in cellStyle.css) {
|
|
|
|
|
+ csses_.push(key + ': ' + cellStyle.css[key]);
|
|
|
}
|
|
}
|
|
|
|
|
+ style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (item._data && !$.isEmptyObject(item._data)) {
|
|
|
|
|
- $.each(item._data, function (k, v) {
|
|
|
|
|
|
|
+ value = calculateObjectValue(column,
|
|
|
|
|
+ that.header.formatters[j], [value_, item, i], value_);
|
|
|
|
|
+
|
|
|
|
|
+ if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
|
|
|
|
|
+ $.each(item['_' + field + '_data'], function(k, v) {
|
|
|
// ignore data-index
|
|
// ignore data-index
|
|
|
if (k === 'index') {
|
|
if (k === 'index') {
|
|
|
return;
|
|
return;
|
|
@@ -1655,160 +1729,100 @@
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- html.push('<tr',
|
|
|
|
|
- sprintf(' %s', htmlAttributes.join(' ')),
|
|
|
|
|
- sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
|
|
|
|
|
- sprintf(' class="%s"', style.classes || ($.isArray(item) ? undefined : item._class)),
|
|
|
|
|
- sprintf(' data-index="%s"', i),
|
|
|
|
|
- sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]),
|
|
|
|
|
- sprintf('%s', data_),
|
|
|
|
|
- '>'
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ if (column.checkbox || column.radio) {
|
|
|
|
|
+ type = column.checkbox ? 'checkbox' : type;
|
|
|
|
|
+ type = column.radio ? 'radio' : type;
|
|
|
|
|
|
|
|
- if (this.options.cardView) {
|
|
|
|
|
- html.push(sprintf('<td colspan="%s"><div class="card-views">', this.header.fields.length));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ text = [sprintf(that.options.cardView ?
|
|
|
|
|
+ '<div class="card-view %s">' : '<td class="bs-checkbox %s">', column['class'] || ''),
|
|
|
|
|
+ '<input' +
|
|
|
|
|
+ sprintf(' data-index="%s"', i) +
|
|
|
|
|
+ sprintf(' name="%s"', that.options.selectItemName) +
|
|
|
|
|
+ sprintf(' type="%s"', type) +
|
|
|
|
|
+ sprintf(' value="%s"', item[that.options.idField]) +
|
|
|
|
|
+ sprintf(' checked="%s"', value === true ||
|
|
|
|
|
+ (value_ || value && value.checked) ? 'checked' : undefined) +
|
|
|
|
|
+ sprintf(' disabled="%s"', !column.checkboxEnabled ||
|
|
|
|
|
+ (value && value.disabled) ? 'disabled' : undefined) +
|
|
|
|
|
+ ' />',
|
|
|
|
|
+ that.header.formatters[j] && typeof value === 'string' ? value : '',
|
|
|
|
|
+ that.options.cardView ? '</div>' : '</td>'
|
|
|
|
|
+ ].join('');
|
|
|
|
|
|
|
|
- if (!this.options.cardView && this.options.detailView) {
|
|
|
|
|
- html.push('<td>',
|
|
|
|
|
- '<a class="detail-icon" href="javascript:">',
|
|
|
|
|
- sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
|
|
|
|
|
- '</a>',
|
|
|
|
|
- '</td>');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ item[that.header.stateField] = value === true || (value && value.checked);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ value = typeof value === 'undefined' || value === null ?
|
|
|
|
|
+ that.options.undefinedText : value;
|
|
|
|
|
+
|
|
|
|
|
+ text = that.options.cardView ? ['<div class="card-view">',
|
|
|
|
|
+ that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
|
|
|
|
|
+ getPropertyFromOther(that.columns, 'field', 'title', field)) : '',
|
|
|
|
|
+ sprintf('<span class="value">%s</span>', value),
|
|
|
|
|
+ '</div>'
|
|
|
|
|
+ ].join('') : [sprintf('<td%s %s %s %s %s %s %s>',
|
|
|
|
|
+ id_, class_, style, data_, rowspan_, colspan_, title_),
|
|
|
|
|
+ value,
|
|
|
|
|
+ '</td>'
|
|
|
|
|
+ ].join('');
|
|
|
|
|
|
|
|
- $.each(this.header.fields, function (j, field) {
|
|
|
|
|
- var text = '',
|
|
|
|
|
- value_ = getItemField(item, field, that.options.escape),
|
|
|
|
|
- value = '',
|
|
|
|
|
- type = '',
|
|
|
|
|
- cellStyle = {},
|
|
|
|
|
- id_ = '',
|
|
|
|
|
- class_ = that.header.classes[j],
|
|
|
|
|
- data_ = '',
|
|
|
|
|
- rowspan_ = '',
|
|
|
|
|
- colspan_ = '',
|
|
|
|
|
- title_ = '',
|
|
|
|
|
- column = that.columns[j];
|
|
|
|
|
-
|
|
|
|
|
- if (that.fromHtml && typeof value_ === 'undefined') {
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ // Hide empty data on Card view when smartDisplay is set to true.
|
|
|
|
|
+ if (that.options.cardView && that.options.smartDisplay && value === '') {
|
|
|
|
|
+ // Should set a placeholder for event binding correct fieldIndex
|
|
|
|
|
+ text = '<div class="card-view"></div>';
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (!column.visible) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ html.push(text);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- if (that.options.cardView && !column.cardVisible) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (this.options.cardView) {
|
|
|
|
|
+ html.push('</div></td>');
|
|
|
|
|
+ }
|
|
|
|
|
+ html.push('</tr>');
|
|
|
|
|
|
|
|
- style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
|
|
|
|
|
|
|
+ return html.join(' ');
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- // handle td's id and class
|
|
|
|
|
- if (item['_' + field + '_id']) {
|
|
|
|
|
- id_ = sprintf(' id="%s"', item['_' + field + '_id']);
|
|
|
|
|
- }
|
|
|
|
|
- if (item['_' + field + '_class']) {
|
|
|
|
|
- class_ = sprintf(' class="%s"', item['_' + field + '_class']);
|
|
|
|
|
- }
|
|
|
|
|
- if (item['_' + field + '_rowspan']) {
|
|
|
|
|
- rowspan_ = sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
|
|
|
|
|
- }
|
|
|
|
|
- if (item['_' + field + '_colspan']) {
|
|
|
|
|
- colspan_ = sprintf(' colspan="%s"', item['_' + field + '_colspan']);
|
|
|
|
|
- }
|
|
|
|
|
- if (item['_' + field + '_title']) {
|
|
|
|
|
- title_ = sprintf(' title="%s"', item['_' + field + '_title']);
|
|
|
|
|
- }
|
|
|
|
|
- cellStyle = calculateObjectValue(that.header,
|
|
|
|
|
- that.header.cellStyles[j], [value_, item, i, field], cellStyle);
|
|
|
|
|
- if (cellStyle.classes) {
|
|
|
|
|
- class_ = sprintf(' class="%s"', cellStyle.classes);
|
|
|
|
|
- }
|
|
|
|
|
- if (cellStyle.css) {
|
|
|
|
|
- var csses_ = [];
|
|
|
|
|
- for (var key in cellStyle.css) {
|
|
|
|
|
- csses_.push(key + ': ' + cellStyle.css[key]);
|
|
|
|
|
- }
|
|
|
|
|
- style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ BootstrapTable.prototype.initBody = function (fixedScroll) {
|
|
|
|
|
+ var that = this,
|
|
|
|
|
+ html = [],
|
|
|
|
|
+ data = this.getData();
|
|
|
|
|
|
|
|
- value = calculateObjectValue(column,
|
|
|
|
|
- that.header.formatters[j], [value_, item, i], value_);
|
|
|
|
|
|
|
+ this.trigger('pre-body', data);
|
|
|
|
|
|
|
|
- if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
|
|
|
|
|
- $.each(item['_' + field + '_data'], function (k, v) {
|
|
|
|
|
- // ignore data-index
|
|
|
|
|
- if (k === 'index') {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- data_ += sprintf(' data-%s="%s"', k, v);
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ this.$body = this.$el.find('>tbody');
|
|
|
|
|
+ if (!this.$body.length) {
|
|
|
|
|
+ this.$body = $('<tbody></tbody>').appendTo(this.$el);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (column.checkbox || column.radio) {
|
|
|
|
|
- type = column.checkbox ? 'checkbox' : type;
|
|
|
|
|
- type = column.radio ? 'radio' : type;
|
|
|
|
|
|
|
+ //Fix #389 Bootstrap-table-flatJSON is not working
|
|
|
|
|
|
|
|
- text = [sprintf(that.options.cardView ?
|
|
|
|
|
- '<div class="card-view %s">' : '<td class="bs-checkbox %s">', column['class'] || ''),
|
|
|
|
|
- '<input' +
|
|
|
|
|
- sprintf(' data-index="%s"', i) +
|
|
|
|
|
- sprintf(' name="%s"', that.options.selectItemName) +
|
|
|
|
|
- sprintf(' type="%s"', type) +
|
|
|
|
|
- sprintf(' value="%s"', item[that.options.idField]) +
|
|
|
|
|
- sprintf(' checked="%s"', value === true ||
|
|
|
|
|
- (value_ || value && value.checked) ? 'checked' : undefined) +
|
|
|
|
|
- sprintf(' disabled="%s"', !column.checkboxEnabled ||
|
|
|
|
|
- (value && value.disabled) ? 'disabled' : undefined) +
|
|
|
|
|
- ' />',
|
|
|
|
|
- that.header.formatters[j] && typeof value === 'string' ? value : '',
|
|
|
|
|
- that.options.cardView ? '</div>' : '</td>'
|
|
|
|
|
- ].join('');
|
|
|
|
|
-
|
|
|
|
|
- item[that.header.stateField] = value === true || (value && value.checked);
|
|
|
|
|
- } else {
|
|
|
|
|
- value = typeof value === 'undefined' || value === null ?
|
|
|
|
|
- that.options.undefinedText : value;
|
|
|
|
|
-
|
|
|
|
|
- text = that.options.cardView ? ['<div class="card-view">',
|
|
|
|
|
- that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
|
|
|
|
|
- getPropertyFromOther(that.columns, 'field', 'title', field)) : '',
|
|
|
|
|
- sprintf('<span class="value">%s</span>', value),
|
|
|
|
|
- '</div>'
|
|
|
|
|
- ].join('') : [sprintf('<td%s %s %s %s %s %s %s>',
|
|
|
|
|
- id_, class_, style, data_, rowspan_, colspan_, title_),
|
|
|
|
|
- value,
|
|
|
|
|
- '</td>'
|
|
|
|
|
- ].join('');
|
|
|
|
|
-
|
|
|
|
|
- // Hide empty data on Card view when smartDisplay is set to true.
|
|
|
|
|
- if (that.options.cardView && that.options.smartDisplay && value === '') {
|
|
|
|
|
- // Should set a placeholder for event binding correct fieldIndex
|
|
|
|
|
- text = '<div class="card-view"></div>';
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (!this.options.pagination || this.options.sidePagination === 'server') {
|
|
|
|
|
+ this.pageFrom = 1;
|
|
|
|
|
+ this.pageTo = data.length;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- html.push(text);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ var trFragments = $(document.createDocumentFragment());
|
|
|
|
|
+ var hasTr;
|
|
|
|
|
|
|
|
- if (this.options.cardView) {
|
|
|
|
|
- html.push('</div></td>');
|
|
|
|
|
|
|
+ for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
|
|
|
|
|
+ var item = data[i];
|
|
|
|
|
+ var tr = this.initRow(item, i, data, trFragments);
|
|
|
|
|
+ hasTr = hasTr || !!tr;
|
|
|
|
|
+ if (tr&&tr!==true) {
|
|
|
|
|
+ trFragments.append(tr);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- html.push('</tr>');
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// show no records
|
|
// show no records
|
|
|
- if (!html.length) {
|
|
|
|
|
- html.push('<tr class="no-records-found">',
|
|
|
|
|
- sprintf('<td colspan="%s">%s</td>',
|
|
|
|
|
- this.$header.find('th').length, this.options.formatNoMatches()),
|
|
|
|
|
|
|
+ if (!hasTr) {
|
|
|
|
|
+ trFragments.append('<tr class="no-records-found">'+
|
|
|
|
|
+ sprintf('<td colspan="%s">%s</td>'+
|
|
|
|
|
+ this.$header.find('th').length, this.options.formatNoMatches())+
|
|
|
'</tr>');
|
|
'</tr>');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.$body.html(html.join(''));
|
|
|
|
|
|
|
+ this.$body.html(trFragments);
|
|
|
|
|
|
|
|
if (!fixedScroll) {
|
|
if (!fixedScroll) {
|
|
|
this.scrollTo(0);
|
|
this.scrollTo(0);
|