|
|
@@ -1,6 +1,6 @@
|
|
|
/**
|
|
|
* @author zhixin wen <wenzhixin2010@gmail.com>
|
|
|
- * version: 1.9.1
|
|
|
+ * version: 1.10.0
|
|
|
* https://github.com/wenzhixin/bootstrap-table/
|
|
|
*/
|
|
|
|
|
|
@@ -180,11 +180,12 @@
|
|
|
var escapeHTML = function (text) {
|
|
|
if (typeof text === 'string') {
|
|
|
return text
|
|
|
- .replace(/&/g, "&")
|
|
|
- .replace(/</g, "<")
|
|
|
- .replace(/>/g, ">")
|
|
|
- .replace(/"/g, """)
|
|
|
- .replace(/'/g, "'");
|
|
|
+ .replace(/&/g, '&')
|
|
|
+ .replace(/</g, '<')
|
|
|
+ .replace(/>/g, '>')
|
|
|
+ .replace(/"/g, '"')
|
|
|
+ .replace(/'/g, ''')
|
|
|
+ .replace(/`/g, '`');
|
|
|
}
|
|
|
return text;
|
|
|
};
|
|
|
@@ -211,17 +212,21 @@
|
|
|
return dataAttr;
|
|
|
};
|
|
|
|
|
|
- var getItemField = function (item, field) {
|
|
|
+ var getItemField = function (item, field, escape) {
|
|
|
var value = item;
|
|
|
|
|
|
if (typeof field !== 'string' || item.hasOwnProperty(field)) {
|
|
|
- return item[field];
|
|
|
+ return escape ? escapeHTML(item[field]) : item[field];
|
|
|
}
|
|
|
var props = field.split('.');
|
|
|
for (var p in props) {
|
|
|
- value = value[props[p]];
|
|
|
+ value = value && value[props[p]];
|
|
|
}
|
|
|
- return value;
|
|
|
+ return escape ? escapeHTML(value) : value;
|
|
|
+ };
|
|
|
+
|
|
|
+ var isIEBrowser = function () {
|
|
|
+ return !!(navigator.userAgent.indexOf("MSIE ") > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./));
|
|
|
};
|
|
|
|
|
|
// BOOTSTRAP TABLE CLASS DEFINITION
|
|
|
@@ -272,11 +277,10 @@
|
|
|
paginationHAlign: 'right', //right, left
|
|
|
paginationVAlign: 'bottom', //bottom, top, both
|
|
|
paginationDetailHAlign: 'left', //right, left
|
|
|
- paginationFirstText: '«',
|
|
|
paginationPreText: '‹',
|
|
|
paginationNextText: '›',
|
|
|
- paginationLastText: '»',
|
|
|
search: false,
|
|
|
+ searchOnEnterKey: false,
|
|
|
strictSearch: false,
|
|
|
searchAlign: 'right',
|
|
|
selectItemName: 'btSelectItem',
|
|
|
@@ -288,6 +292,7 @@
|
|
|
showToggle: false,
|
|
|
buttonsAlign: 'right',
|
|
|
smartDisplay: true,
|
|
|
+ escape: true,
|
|
|
minimumCountColumns: 1,
|
|
|
idField: undefined,
|
|
|
uniqueId: undefined,
|
|
|
@@ -619,7 +624,7 @@
|
|
|
});
|
|
|
|
|
|
// if options.data is setting, do not process tbody data
|
|
|
- if (this.options.data.length) {
|
|
|
+ if (this.options.data) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -763,7 +768,11 @@
|
|
|
$(this).data(visibleColumns[$(this).data('field')]);
|
|
|
});
|
|
|
this.$container.off('click', '.th-inner').on('click', '.th-inner', function (event) {
|
|
|
- if (that.options.sortable && $(this).parent().data().sortable) {
|
|
|
+ var target = $(this);
|
|
|
+ if (target.closest('.bootstrap-table')[0] !== that.$container[0])
|
|
|
+ return false;
|
|
|
+
|
|
|
+ if (that.options.sortable && target.parent().data().sortable) {
|
|
|
that.onSort(event);
|
|
|
}
|
|
|
});
|
|
|
@@ -790,8 +799,7 @@
|
|
|
}
|
|
|
|
|
|
this.$selectAll = this.$header.find('[name="btSelectAll"]');
|
|
|
- this.$container.off('click', '[name="btSelectAll"]')
|
|
|
- .on('click', '[name="btSelectAll"]', function () {
|
|
|
+ this.$selectAll.off('click').on('click', function () {
|
|
|
var checked = $(this).prop('checked');
|
|
|
that[checked ? 'checkAll' : 'uncheckAll']();
|
|
|
that.updateSelected();
|
|
|
@@ -845,8 +853,8 @@
|
|
|
if (that.header.sortNames[index]) {
|
|
|
name = that.header.sortNames[index];
|
|
|
}
|
|
|
- var aa = getItemField(a, name),
|
|
|
- bb = getItemField(b, name),
|
|
|
+ var aa = getItemField(a, name, that.options.escape),
|
|
|
+ bb = getItemField(b, name, that.options.escape),
|
|
|
value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
|
|
|
|
|
|
if (value !== undefined) {
|
|
|
@@ -926,6 +934,9 @@
|
|
|
$search,
|
|
|
switchableCount = 0;
|
|
|
|
|
|
+ if (this.$toolbar.find('.bars').children().length) {
|
|
|
+ $('body').append($(this.options.toolbar));
|
|
|
+ }
|
|
|
this.$toolbar.html('');
|
|
|
|
|
|
if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') {
|
|
|
@@ -1002,7 +1013,7 @@
|
|
|
|
|
|
html.push('</div>');
|
|
|
|
|
|
- // Fix #188: this.showToolbar is for extentions
|
|
|
+ // Fix #188: this.showToolbar is for extensions
|
|
|
if (this.showToolbar || html.length > 2) {
|
|
|
this.$toolbar.append(html.join(''));
|
|
|
}
|
|
|
@@ -1056,11 +1067,26 @@
|
|
|
this.$toolbar.append(html.join(''));
|
|
|
$search = this.$toolbar.find('.search input');
|
|
|
$search.off('keyup drop').on('keyup drop', function (event) {
|
|
|
+ if (that.options.searchOnEnterKey) {
|
|
|
+ if (event.keyCode !== 13) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
clearTimeout(timeoutId); // doesn't matter if it's 0
|
|
|
timeoutId = setTimeout(function () {
|
|
|
that.onSearch(event);
|
|
|
}, that.options.searchTimeOut);
|
|
|
});
|
|
|
+
|
|
|
+ if (isIEBrowser()) {
|
|
|
+ $search.off('mouseup').on('mouseup', function (event) {
|
|
|
+ clearTimeout(timeoutId); // doesn't matter if it's 0
|
|
|
+ timeoutId = setTimeout(function () {
|
|
|
+ that.onSearch(event);
|
|
|
+ }, that.options.searchTimeOut);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -1076,6 +1102,7 @@
|
|
|
return;
|
|
|
}
|
|
|
this.searchText = text;
|
|
|
+ this.options.searchText = text;
|
|
|
|
|
|
this.options.pageNumber = 1;
|
|
|
this.initSearch();
|
|
|
@@ -1111,7 +1138,7 @@
|
|
|
column = that.columns[getFieldIndex(that.columns, key)],
|
|
|
j = $.inArray(key, that.header.fields);
|
|
|
|
|
|
- // Fix #142: search use formated data
|
|
|
+ // Fix #142: search use formatted data
|
|
|
if (column && column.searchFormatter) {
|
|
|
value = calculateObjectValue(column,
|
|
|
that.header.formatters[j], [value, item, i], value);
|
|
|
@@ -1243,7 +1270,6 @@
|
|
|
html.push('</div>',
|
|
|
'<div class="pull-' + this.options.paginationHAlign + ' pagination">',
|
|
|
'<ul class="pagination' + sprintf(' pagination-%s', this.options.iconSize) + '">',
|
|
|
- '<li class="page-first"><a href="javascript:void(0)">' + this.options.paginationFirstText + '</a></li>',
|
|
|
'<li class="page-pre"><a href="javascript:void(0)">' + this.options.paginationPreText + '</a></li>');
|
|
|
|
|
|
if (this.totalPages < 5) {
|
|
|
@@ -1261,18 +1287,71 @@
|
|
|
from = to - 4;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (this.totalPages >= 6) {
|
|
|
+ if (this.options.pageNumber >= 3) {
|
|
|
+ html.push('<li class="page-first' + (1 === this.options.pageNumber ? ' active' : '') + '">',
|
|
|
+ '<a href="javascript:void(0)">', 1, '</a>',
|
|
|
+ '</li>');
|
|
|
+
|
|
|
+ from++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.options.pageNumber >= 4) {
|
|
|
+ if (this.options.pageNumber == 4 || this.totalPages == 6 || this.totalPages == 7) {
|
|
|
+ from--;
|
|
|
+ } else {
|
|
|
+ html.push('<li class="page-first-separator disabled">',
|
|
|
+ '<a href="javascript:void(0)">...</a>',
|
|
|
+ '</li>');
|
|
|
+ }
|
|
|
+
|
|
|
+ to--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.totalPages >= 7) {
|
|
|
+ if (this.options.pageNumber >= (this.totalPages - 2)) {
|
|
|
+ from--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.totalPages == 6) {
|
|
|
+ if (this.options.pageNumber >= (this.totalPages - 2)) {
|
|
|
+ to++;
|
|
|
+ }
|
|
|
+ } else if (this.totalPages >= 7) {
|
|
|
+ if (this.totalPages == 7 || this.options.pageNumber >= (this.totalPages - 3)) {
|
|
|
+ to++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
for (i = from; i <= to; i++) {
|
|
|
html.push('<li class="page-number' + (i === this.options.pageNumber ? ' active' : '') + '">',
|
|
|
'<a href="javascript:void(0)">', i, '</a>',
|
|
|
'</li>');
|
|
|
}
|
|
|
|
|
|
+ if (this.totalPages >= 8) {
|
|
|
+ if (this.options.pageNumber <= (this.totalPages - 4)) {
|
|
|
+ html.push('<li class="page-last-separator disabled">',
|
|
|
+ '<a href="javascript:void(0)">...</a>',
|
|
|
+ '</li>');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.totalPages >= 6) {
|
|
|
+ if (this.options.pageNumber <= (this.totalPages - 3)) {
|
|
|
+ html.push('<li class="page-last' + (this.totalPages === this.options.pageNumber ? ' active' : '') + '">',
|
|
|
+ '<a href="javascript:void(0)">', this.totalPages, '</a>',
|
|
|
+ '</li>');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
html.push(
|
|
|
'<li class="page-next"><a href="javascript:void(0)">' + this.options.paginationNextText + '</a></li>',
|
|
|
- '<li class="page-last"><a href="javascript:void(0)">' + this.options.paginationLastText + '</a></li>',
|
|
|
'</ul>',
|
|
|
'</div>');
|
|
|
-
|
|
|
}
|
|
|
this.$pagination.html(html.join(''));
|
|
|
|
|
|
@@ -1284,14 +1363,6 @@
|
|
|
$last = this.$pagination.find('.page-last');
|
|
|
$number = this.$pagination.find('.page-number');
|
|
|
|
|
|
- if (this.options.pageNumber <= 1) {
|
|
|
- $first.addClass('disabled');
|
|
|
- $pre.addClass('disabled');
|
|
|
- }
|
|
|
- if (this.options.pageNumber >= this.totalPages) {
|
|
|
- $next.addClass('disabled');
|
|
|
- $last.addClass('disabled');
|
|
|
- }
|
|
|
if (this.options.smartDisplay) {
|
|
|
if (this.totalPages <= 1) {
|
|
|
this.$pagination.find('div.pagination').hide();
|
|
|
@@ -1352,12 +1423,20 @@
|
|
|
};
|
|
|
|
|
|
BootstrapTable.prototype.onPagePre = function (event) {
|
|
|
- this.options.pageNumber--;
|
|
|
+ if ((this.options.pageNumber - 1) == 0) {
|
|
|
+ this.options.pageNumber = this.options.totalPages;
|
|
|
+ } else {
|
|
|
+ this.options.pageNumber--;
|
|
|
+ }
|
|
|
this.updatePagination(event);
|
|
|
};
|
|
|
|
|
|
BootstrapTable.prototype.onPageNext = function (event) {
|
|
|
- this.options.pageNumber++;
|
|
|
+ if ((this.options.pageNumber + 1) > this.options.totalPages) {
|
|
|
+ this.options.pageNumber = 1;
|
|
|
+ } else {
|
|
|
+ this.options.pageNumber++;
|
|
|
+ }
|
|
|
this.updatePagination(event);
|
|
|
};
|
|
|
|
|
|
@@ -1453,7 +1532,7 @@
|
|
|
|
|
|
$.each(this.header.fields, function (j, field) {
|
|
|
var text = '',
|
|
|
- value = getItemField(item, field),
|
|
|
+ value = getItemField(item, field, that.options.escape),
|
|
|
type = '',
|
|
|
cellStyle = {},
|
|
|
id_ = '',
|
|
|
@@ -1512,8 +1591,8 @@
|
|
|
type = column.checkbox ? 'checkbox' : type;
|
|
|
type = column.radio ? 'radio' : type;
|
|
|
|
|
|
- text = [that.options.cardView ?
|
|
|
- '<div class="card-view">' : '<td class="bs-checkbox">',
|
|
|
+ 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) +
|
|
|
@@ -1582,7 +1661,7 @@
|
|
|
index = $td[0].cellIndex,
|
|
|
field = that.header.fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
|
|
|
column = that.columns[getFieldIndex(that.columns, field)],
|
|
|
- value = getItemField(item, field);
|
|
|
+ value = getItemField(item, field, that.options.escape);
|
|
|
|
|
|
if ($td.find('.detail-icon').length) {
|
|
|
return;
|
|
|
@@ -1613,10 +1692,13 @@
|
|
|
that.trigger('collapse-row', index, row);
|
|
|
} else {
|
|
|
$this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailClose));
|
|
|
- $tr.after(sprintf('<tr class="detail-view"><td colspan="%s">%s</td></tr>',
|
|
|
- $tr.find('td').length, calculateObjectValue(that.options,
|
|
|
- that.options.detailFormatter, [index, row], '')));
|
|
|
- that.trigger('expand-row', index, row, $tr.next().find('td'));
|
|
|
+ $tr.after(sprintf('<tr class="detail-view"><td colspan="%s"></td></tr>', $tr.find('td').length));
|
|
|
+ var $element = $tr.next().find('td');
|
|
|
+ var content = calculateObjectValue(that.options, that.options.detailFormatter, [index, row, $element], '');
|
|
|
+ if($element.length === 1) {
|
|
|
+ $element.append(content);
|
|
|
+ }
|
|
|
+ that.trigger('expand-row', index, row, $element);
|
|
|
}
|
|
|
that.resetView();
|
|
|
});
|
|
|
@@ -1694,15 +1776,18 @@
|
|
|
var that = this,
|
|
|
data = {},
|
|
|
params = {
|
|
|
- pageSize: this.options.pageSize === this.options.formatAllRows() ?
|
|
|
- this.options.totalRows : this.options.pageSize,
|
|
|
- pageNumber: this.options.pageNumber,
|
|
|
searchText: this.searchText,
|
|
|
sortName: this.options.sortName,
|
|
|
sortOrder: this.options.sortOrder
|
|
|
},
|
|
|
request;
|
|
|
|
|
|
+ if(this.options.pagination) {
|
|
|
+ params.pageSize = this.options.pageSize === this.options.formatAllRows() ?
|
|
|
+ this.options.totalRows : this.options.pageSize;
|
|
|
+ params.pageNumber = this.options.pageNumber;
|
|
|
+ }
|
|
|
+
|
|
|
if (!this.options.url && !this.options.ajax) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -1750,14 +1835,11 @@
|
|
|
|
|
|
that.load(res);
|
|
|
that.trigger('load-success', res);
|
|
|
+ if (!silent) that.$tableLoading.hide();
|
|
|
},
|
|
|
error: function (res) {
|
|
|
that.trigger('load-error', res.status, res);
|
|
|
- },
|
|
|
- complete: function () {
|
|
|
- if (!silent) {
|
|
|
- that.$tableLoading.hide();
|
|
|
- }
|
|
|
+ if (!silent) that.$tableLoading.hide();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
@@ -2120,6 +2202,7 @@
|
|
|
this.initData(data, 'append');
|
|
|
this.initSearch();
|
|
|
this.initPagination();
|
|
|
+ this.initSort();
|
|
|
this.initBody(true);
|
|
|
};
|
|
|
|
|
|
@@ -2127,6 +2210,7 @@
|
|
|
this.initData(data, 'prepend');
|
|
|
this.initSearch();
|
|
|
this.initPagination();
|
|
|
+ this.initSort();
|
|
|
this.initBody(true);
|
|
|
};
|
|
|
|
|
|
@@ -2155,6 +2239,7 @@
|
|
|
|
|
|
this.initSearch();
|
|
|
this.initPagination();
|
|
|
+ this.initSort();
|
|
|
this.initBody(true);
|
|
|
};
|
|
|
|
|
|
@@ -2259,14 +2344,14 @@
|
|
|
};
|
|
|
|
|
|
BootstrapTable.prototype.showRow = function (params) {
|
|
|
- if (!params.hasOwnProperty('index') || !params.hasOwnProperty('uniqueId')) {
|
|
|
+ if (!params.hasOwnProperty('index') && !params.hasOwnProperty('uniqueId')) {
|
|
|
return;
|
|
|
}
|
|
|
this.toggleRow(params.index, params.uniqueId, true);
|
|
|
};
|
|
|
|
|
|
BootstrapTable.prototype.hideRow = function (params) {
|
|
|
- if (!params.hasOwnProperty('index') || !params.hasOwnProperty('uniqueId')) {
|
|
|
+ if (!params.hasOwnProperty('index') && !params.hasOwnProperty('uniqueId')) {
|
|
|
return;
|
|
|
}
|
|
|
this.toggleRow(params.index, params.uniqueId, false);
|
|
|
@@ -2318,6 +2403,10 @@
|
|
|
return;
|
|
|
}
|
|
|
this.data[params.index][params.field] = params.value;
|
|
|
+
|
|
|
+ if (params.reinit === false) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.initSort();
|
|
|
this.initBody(true);
|
|
|
};
|
|
|
@@ -2525,7 +2614,7 @@
|
|
|
|
|
|
BootstrapTable.prototype.refreshOptions = function (options) {
|
|
|
//If the objects are equivalent then avoid the call of destroy / init methods
|
|
|
- if (compareObjects(this.options, options, false)) {
|
|
|
+ if (compareObjects(this.options, options, true)) {
|
|
|
return;
|
|
|
}
|
|
|
this.options = $.extend(this.options, options);
|
|
|
@@ -2604,6 +2693,21 @@
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ BootstrapTable.prototype.updateFormatText = function (name, text) {
|
|
|
+ if (this.options[sprintf('format%s', name)]) {
|
|
|
+ if (typeof text === 'string') {
|
|
|
+ this.options[sprintf('format%s', name)] = function () {
|
|
|
+ return text;
|
|
|
+ };
|
|
|
+ } else if (typeof text === 'function') {
|
|
|
+ this.options[sprintf('format%s', name)] = text;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.initToolbar();
|
|
|
+ this.initPagination();
|
|
|
+ this.initBody();
|
|
|
+ };
|
|
|
+
|
|
|
// BOOTSTRAP TABLE PLUGIN DEFINITION
|
|
|
// =======================
|
|
|
|
|
|
@@ -2631,7 +2735,8 @@
|
|
|
'toggleView',
|
|
|
'refreshOptions',
|
|
|
'resetSearch',
|
|
|
- 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows'
|
|
|
+ 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows',
|
|
|
+ 'updateFormatText'
|
|
|
];
|
|
|
|
|
|
$.fn.bootstrapTable = function (option) {
|
|
|
@@ -2686,5 +2791,4 @@
|
|
|
$(function () {
|
|
|
$('[data-toggle="table"]').bootstrapTable();
|
|
|
});
|
|
|
-
|
|
|
}(jQuery);
|