|
|
@@ -263,6 +263,7 @@
|
|
|
return res;
|
|
|
},
|
|
|
pagination: false,
|
|
|
+ onlyInfoPagination: false,
|
|
|
sidePagination: 'client', // client or server
|
|
|
totalRows: 0, // server side need to set
|
|
|
pageNumber: 1,
|
|
|
@@ -415,6 +416,9 @@
|
|
|
formatShowingRows: function (pageFrom, pageTo, totalRows) {
|
|
|
return sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows);
|
|
|
},
|
|
|
+ formatDetailPagination: function (totalRows) {
|
|
|
+ return sprintf('Showing %s rows', totalRows);
|
|
|
+ },
|
|
|
formatSearch: function () {
|
|
|
return 'Search';
|
|
|
},
|
|
|
@@ -790,6 +794,7 @@
|
|
|
.on('click', '[name="btSelectAll"]', function () {
|
|
|
var checked = $(this).prop('checked');
|
|
|
that[checked ? 'checkAll' : 'uncheckAll']();
|
|
|
+ that.updateSelected();
|
|
|
});
|
|
|
};
|
|
|
|
|
|
@@ -945,14 +950,18 @@
|
|
|
}
|
|
|
|
|
|
if (this.options.showRefresh) {
|
|
|
- html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="refresh" title="%s">',
|
|
|
+ html.push(sprintf('<button class="btn btn-default' +
|
|
|
+ sprintf(' btn-%s', this.options.iconSize) +
|
|
|
+ '" type="button" name="refresh" title="%s">',
|
|
|
this.options.formatRefresh()),
|
|
|
sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh),
|
|
|
'</button>');
|
|
|
}
|
|
|
|
|
|
if (this.options.showToggle) {
|
|
|
- html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="toggle" title="%s">',
|
|
|
+ html.push(sprintf('<button class="btn btn-default' +
|
|
|
+ sprintf(' btn-%s', this.options.iconSize) +
|
|
|
+ '" type="button" name="toggle" title="%s">',
|
|
|
this.options.formatToggle()),
|
|
|
sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggle),
|
|
|
'</button>');
|
|
|
@@ -961,7 +970,9 @@
|
|
|
if (this.options.showColumns) {
|
|
|
html.push(sprintf('<div class="keep-open btn-group" title="%s">',
|
|
|
this.options.formatColumns()),
|
|
|
- '<button type="button" class="btn btn-default' + (this.options.iconSize == undefined ? '' : ' btn-' + this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">',
|
|
|
+ '<button type="button" class="btn btn-default' +
|
|
|
+ sprintf(' btn-%s', this.options.iconSize) +
|
|
|
+ ' dropdown-toggle" data-toggle="dropdown">',
|
|
|
sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns),
|
|
|
' <span class="caret"></span>',
|
|
|
'</button>',
|
|
|
@@ -1036,7 +1047,9 @@
|
|
|
html = [];
|
|
|
html.push(
|
|
|
'<div class="pull-' + this.options.searchAlign + ' search">',
|
|
|
- sprintf('<input class="form-control' + (this.options.iconSize === undefined ? '' : ' input-' + this.options.iconSize) + '" type="text" placeholder="%s">',
|
|
|
+ sprintf('<input class="form-control' +
|
|
|
+ sprintf(' input-%s', this.options.iconSize) +
|
|
|
+ '" type="text" placeholder="%s">',
|
|
|
this.options.formatSearch()),
|
|
|
'</div>');
|
|
|
|
|
|
@@ -1080,7 +1093,11 @@
|
|
|
// Check filter
|
|
|
this.data = f ? $.grep(this.options.data, function (item, i) {
|
|
|
for (var key in f) {
|
|
|
- if (item[key] !== f[key]) {
|
|
|
+ if ($.isArray(f[key])) {
|
|
|
+ if ($.inArray(item[key], f[key]) === -1) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else if (item[key] !== f[key]) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -1151,7 +1168,7 @@
|
|
|
var pageLst = typeof this.options.pageList === 'string' ?
|
|
|
this.options.pageList.replace('[', '').replace(']', '')
|
|
|
.replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
|
|
|
- if (pageLst.indexOf(this.options.formatAllRows().toLowerCase()) > -1) {
|
|
|
+ if ($.inArray(this.options.formatAllRows().toLowerCase(), pageLst) > -1) {
|
|
|
$allSelected = true;
|
|
|
}
|
|
|
}
|
|
|
@@ -1173,124 +1190,129 @@
|
|
|
html.push(
|
|
|
'<div class="pull-' + this.options.paginationDetailHAlign + ' pagination-detail">',
|
|
|
'<span class="pagination-info">',
|
|
|
+ this.options.onlyInfoPagination ? this.options.formatDetailPagination(this.options.totalRows) :
|
|
|
this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows),
|
|
|
'</span>');
|
|
|
|
|
|
- html.push('<span class="page-list">');
|
|
|
-
|
|
|
- var pageNumber = [
|
|
|
- sprintf('<span class="btn-group %s">',
|
|
|
- this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
|
|
|
- 'dropdown' : 'dropup'),
|
|
|
- '<button type="button" class="btn btn-default ' +
|
|
|
- (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) +
|
|
|
- ' dropdown-toggle" data-toggle="dropdown">',
|
|
|
- '<span class="page-size">',
|
|
|
- $allSelected ? this.options.formatAllRows() : this.options.pageSize,
|
|
|
- '</span>',
|
|
|
- ' <span class="caret"></span>',
|
|
|
- '</button>',
|
|
|
- '<ul class="dropdown-menu" role="menu">'
|
|
|
- ],
|
|
|
- pageList = this.options.pageList;
|
|
|
-
|
|
|
- if (typeof this.options.pageList === 'string') {
|
|
|
- var list = this.options.pageList.replace('[', '').replace(']', '')
|
|
|
- .replace(/ /g, '').split(',');
|
|
|
-
|
|
|
- pageList = [];
|
|
|
- $.each(list, function (i, value) {
|
|
|
- pageList.push(value.toUpperCase() === that.options.formatAllRows().toUpperCase() ?
|
|
|
- that.options.formatAllRows() : +value);
|
|
|
- });
|
|
|
- }
|
|
|
+ if (!this.options.onlyInfoPagination) {
|
|
|
+ html.push('<span class="page-list">');
|
|
|
+
|
|
|
+ var pageNumber = [
|
|
|
+ sprintf('<span class="btn-group %s">',
|
|
|
+ this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
|
|
|
+ 'dropdown' : 'dropup'),
|
|
|
+ '<button type="button" class="btn btn-default ' +
|
|
|
+ sprintf(' btn-%s', this.options.iconSize) +
|
|
|
+ ' dropdown-toggle" data-toggle="dropdown">',
|
|
|
+ '<span class="page-size">',
|
|
|
+ $allSelected ? this.options.formatAllRows() : this.options.pageSize,
|
|
|
+ '</span>',
|
|
|
+ ' <span class="caret"></span>',
|
|
|
+ '</button>',
|
|
|
+ '<ul class="dropdown-menu" role="menu">'
|
|
|
+ ],
|
|
|
+ pageList = this.options.pageList;
|
|
|
+
|
|
|
+ if (typeof this.options.pageList === 'string') {
|
|
|
+ var list = this.options.pageList.replace('[', '').replace(']', '')
|
|
|
+ .replace(/ /g, '').split(',');
|
|
|
+
|
|
|
+ pageList = [];
|
|
|
+ $.each(list, function (i, value) {
|
|
|
+ pageList.push(value.toUpperCase() === that.options.formatAllRows().toUpperCase() ?
|
|
|
+ that.options.formatAllRows() : +value);
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- $.each(pageList, function (i, page) {
|
|
|
- if (!that.options.smartDisplay || i === 0 || pageList[i - 1] <= that.options.totalRows) {
|
|
|
- var active;
|
|
|
- if ($allSelected) {
|
|
|
- active = page === that.options.formatAllRows() ? ' class="active"' : '';
|
|
|
- } else {
|
|
|
- active = page === that.options.pageSize ? ' class="active"' : '';
|
|
|
+ $.each(pageList, function (i, page) {
|
|
|
+ if (!that.options.smartDisplay || i === 0 || pageList[i - 1] <= that.options.totalRows) {
|
|
|
+ var active;
|
|
|
+ if ($allSelected) {
|
|
|
+ active = page === that.options.formatAllRows() ? ' class="active"' : '';
|
|
|
+ } else {
|
|
|
+ active = page === that.options.pageSize ? ' class="active"' : '';
|
|
|
+ }
|
|
|
+ pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
|
|
|
}
|
|
|
- pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
|
|
|
- }
|
|
|
- });
|
|
|
- pageNumber.push('</ul></span>');
|
|
|
+ });
|
|
|
+ pageNumber.push('</ul></span>');
|
|
|
|
|
|
- html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
|
|
|
- html.push('</span>');
|
|
|
+ html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
|
|
|
+ html.push('</span>');
|
|
|
|
|
|
- html.push('</div>',
|
|
|
- '<div class="pull-' + this.options.paginationHAlign + ' pagination">',
|
|
|
- '<ul class="pagination' + (this.options.iconSize === undefined ? '' : ' pagination-' + 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>');
|
|
|
+ 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) {
|
|
|
- from = 1;
|
|
|
- to = this.totalPages;
|
|
|
- } else {
|
|
|
- from = this.options.pageNumber - 2;
|
|
|
- to = from + 4;
|
|
|
- if (from < 1) {
|
|
|
+ if (this.totalPages < 5) {
|
|
|
from = 1;
|
|
|
- to = 5;
|
|
|
- }
|
|
|
- if (to > this.totalPages) {
|
|
|
to = this.totalPages;
|
|
|
- from = to - 4;
|
|
|
+ } else {
|
|
|
+ from = this.options.pageNumber - 2;
|
|
|
+ to = from + 4;
|
|
|
+ if (from < 1) {
|
|
|
+ from = 1;
|
|
|
+ to = 5;
|
|
|
+ }
|
|
|
+ if (to > this.totalPages) {
|
|
|
+ to = this.totalPages;
|
|
|
+ from = to - 4;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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>');
|
|
|
}
|
|
|
- }
|
|
|
- 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>');
|
|
|
- }
|
|
|
|
|
|
- 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>');
|
|
|
+ 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(''));
|
|
|
|
|
|
- $pageList = this.$pagination.find('.page-list a');
|
|
|
- $first = this.$pagination.find('.page-first');
|
|
|
- $pre = this.$pagination.find('.page-pre');
|
|
|
- $next = this.$pagination.find('.page-next');
|
|
|
- $last = this.$pagination.find('.page-last');
|
|
|
- $number = this.$pagination.find('.page-number');
|
|
|
+ if (!this.options.onlyInfoPagination) {
|
|
|
+ $pageList = this.$pagination.find('.page-list a');
|
|
|
+ $first = this.$pagination.find('.page-first');
|
|
|
+ $pre = this.$pagination.find('.page-pre');
|
|
|
+ $next = this.$pagination.find('.page-next');
|
|
|
+ $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();
|
|
|
+ }
|
|
|
+ if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
|
|
|
+ this.$pagination.find('span.page-list').hide();
|
|
|
+ }
|
|
|
|
|
|
- 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();
|
|
|
+ // when data is empty, hide the pagination
|
|
|
+ this.$pagination[this.getData().length ? 'show' : 'hide']();
|
|
|
}
|
|
|
- if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
|
|
|
- this.$pagination.find('span.page-list').hide();
|
|
|
+ if ($allSelected) {
|
|
|
+ this.options.pageSize = this.options.formatAllRows();
|
|
|
}
|
|
|
-
|
|
|
- // when data is empty, hide the pagination
|
|
|
- this.$pagination[this.getData().length ? 'show' : 'hide']();
|
|
|
+ $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
|
|
|
+ $first.off('click').on('click', $.proxy(this.onPageFirst, this));
|
|
|
+ $pre.off('click').on('click', $.proxy(this.onPagePre, this));
|
|
|
+ $next.off('click').on('click', $.proxy(this.onPageNext, this));
|
|
|
+ $last.off('click').on('click', $.proxy(this.onPageLast, this));
|
|
|
+ $number.off('click').on('click', $.proxy(this.onPageNumber, this));
|
|
|
}
|
|
|
- if ($allSelected) {
|
|
|
- this.options.pageSize = this.options.formatAllRows();
|
|
|
- }
|
|
|
- $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
|
|
|
- $first.off('click').on('click', $.proxy(this.onPageFirst, this));
|
|
|
- $pre.off('click').on('click', $.proxy(this.onPagePre, this));
|
|
|
- $next.off('click').on('click', $.proxy(this.onPageNext, this));
|
|
|
- $last.off('click').on('click', $.proxy(this.onPageLast, this));
|
|
|
- $number.off('click').on('click', $.proxy(this.onPageNumber, this));
|
|
|
};
|
|
|
|
|
|
BootstrapTable.prototype.updatePagination = function (event) {
|
|
|
@@ -1523,7 +1545,8 @@
|
|
|
|
|
|
// Hide empty data on Card view when smartDisplay is set to true.
|
|
|
if (that.options.cardView && that.options.smartDisplay && value === '') {
|
|
|
- text = '';
|
|
|
+ // Should set a placeholder for event binding correct fieldIndex
|
|
|
+ text = '<div class="card-view"></div>';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1642,7 +1665,7 @@
|
|
|
}
|
|
|
|
|
|
for (var key in events) {
|
|
|
- that.$body.find('>tr').each(function () {
|
|
|
+ that.$body.find('>tr:not(.no-records-found)').each(function () {
|
|
|
var $tr = $(this),
|
|
|
$td = $tr.find(that.options.cardView ? '.card-view' : 'td').eq(fieldIndex),
|
|
|
index = key.indexOf(' '),
|
|
|
@@ -2148,26 +2171,30 @@
|
|
|
var uniqueId = this.options.uniqueId,
|
|
|
len = this.options.data.length,
|
|
|
dataRow = null,
|
|
|
- i, row;
|
|
|
+ i, row, rowUniqueId;
|
|
|
|
|
|
for (i = len - 1; i >= 0; i--) {
|
|
|
row = this.options.data[i];
|
|
|
|
|
|
- if (!row.hasOwnProperty(uniqueId)) {
|
|
|
+ if (row.hasOwnProperty(uniqueId)) { // uniqueId is a column
|
|
|
+ rowUniqueId = row[uniqueId];
|
|
|
+ } else if(row._data.hasOwnProperty(uniqueId)) { // uniqueId is a row data property
|
|
|
+ rowUniqueId = row._data[uniqueId];
|
|
|
+ } else {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (typeof row[uniqueId] === 'string') {
|
|
|
+ if (typeof rowUniqueId === 'string') {
|
|
|
id = id.toString();
|
|
|
- } else if (typeof row[uniqueId] === 'number') {
|
|
|
- if ((Number(row[uniqueId]) === row[uniqueId]) && (row[uniqueId] % 1 === 0)) {
|
|
|
+ } else if (typeof rowUniqueId === 'number') {
|
|
|
+ if ((Number(rowUniqueId) === rowUniqueId) && (rowUniqueId % 1 === 0)) {
|
|
|
id = parseInt(id);
|
|
|
- } else if ((row[uniqueId] === Number(row[uniqueId])) && (row[uniqueId] !== 0)) {
|
|
|
+ } else if ((rowUniqueId === Number(rowUniqueId)) && (rowUniqueId !== 0)) {
|
|
|
id = parseFloat(id);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (row[uniqueId] === id) {
|
|
|
+ if (rowUniqueId === id) {
|
|
|
dataRow = row;
|
|
|
break;
|
|
|
}
|
|
|
@@ -2193,6 +2220,24 @@
|
|
|
this.initBody(true);
|
|
|
};
|
|
|
|
|
|
+ BootstrapTable.prototype.updateByUniqueId = function (params) {
|
|
|
+ var rowId;
|
|
|
+
|
|
|
+ if (!params.hasOwnProperty('id') || !params.hasOwnProperty('row')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ rowId = $.inArray(this.getRowByUniqueId(params.id), this.options.data);
|
|
|
+
|
|
|
+ if (rowId === -1) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $.extend(this.data[rowId], params.row);
|
|
|
+ this.initSort();
|
|
|
+ this.initBody(true);
|
|
|
+ };
|
|
|
+
|
|
|
BootstrapTable.prototype.insertRow = function (params) {
|
|
|
if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
|
|
|
return;
|
|
|
@@ -2328,10 +2373,10 @@
|
|
|
};
|
|
|
|
|
|
BootstrapTable.prototype.check_ = function (checked, index) {
|
|
|
- this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
|
|
|
+ var $el = this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
|
|
|
this.data[index][this.header.stateField] = checked;
|
|
|
this.updateSelected();
|
|
|
- this.trigger(checked ? 'check' : 'uncheck', this.data[index]);
|
|
|
+ this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el);
|
|
|
};
|
|
|
|
|
|
BootstrapTable.prototype.checkBy = function (obj) {
|
|
|
@@ -2354,11 +2399,11 @@
|
|
|
return false;
|
|
|
}
|
|
|
if ($.inArray(row[obj.field], obj.values) !== -1) {
|
|
|
- that.$selectItem.filter(':enabled')
|
|
|
+ var $el = that.$selectItem.filter(':enabled')
|
|
|
.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
|
|
|
row[that.header.stateField] = checked;
|
|
|
rows.push(row);
|
|
|
- that.trigger(checked ? 'check' : 'uncheck', row);
|
|
|
+ that.trigger(checked ? 'check' : 'uncheck', row, $el);
|
|
|
}
|
|
|
});
|
|
|
this.updateSelected();
|
|
|
@@ -2566,7 +2611,7 @@
|
|
|
'getOptions',
|
|
|
'getSelections', 'getAllSelections', 'getData',
|
|
|
'load', 'append', 'prepend', 'remove', 'removeAll',
|
|
|
- 'insertRow', 'updateRow', 'updateCell', 'removeByUniqueId',
|
|
|
+ 'insertRow', 'updateRow', 'updateCell', 'updateByUniqueId', 'removeByUniqueId',
|
|
|
'getRowByUniqueId', 'showRow', 'hideRow', 'getRowsHidden',
|
|
|
'mergeCells',
|
|
|
'checkAll', 'uncheckAll',
|