Skip to content

Commit a2c149f

Browse files
committed
优化跨页选择时的导出功能
1 parent 7c5a1de commit a2c149f

File tree

6 files changed

+92
-112
lines changed

6 files changed

+92
-112
lines changed

dist/extensions/export/bootstrap-table-export.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@
114114
data = {total: that.options.totalRows};
115115
data[that.options.dataField] = that.getData();
116116

117+
var Table = typeof require === 'function' ? require('table') : null;
117118
selectedData = {total: that.options.totalRows};
118-
selectedData[that.options.dataField] = that.getAllSelections();
119+
selectedData[that.options.dataField] = Table && that.options.maintainSelected ? Table.api.selecteddata(that.$el) : that.getAllSelections();
119120
}
120121

121122
that.load(selectedData);

dist/extensions/export/bootstrap-table-export.min.js

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/extensions/fixed-columns/bootstrap-table-fixed-columns.js

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
'use strict';
22

3-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
4-
return typeof obj;
5-
} : function (obj) {
6-
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
7-
};
8-
93
(function ($) {
104
'use strict';
115
// Reasonable defaults
@@ -198,8 +192,6 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
198192
};
199193

200194
BootstrapTable.prototype.updateSelected = function () {
201-
var _this = this;
202-
203195
var that = this;
204196

205197
_updateSelected.apply(this, Array.prototype.slice.apply(arguments));
@@ -210,9 +202,9 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
210202
var $el = $(el);
211203
var index = $el.data('index');
212204
var classes = $el.attr('class');
213-
var inputSelector = '[name="' + _this.options.selectItemName + '"]';
205+
var inputSelector = '[name="' + that.options.selectItemName + '"]';
214206
var $input = $el.find(inputSelector);
215-
if ((typeof index === 'undefined' ? 'undefined' : _typeof(index)) === undefined) {
207+
if (typeof index === 'undefined') {
216208
return;
217209
}
218210

@@ -223,16 +215,16 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
223215
if ($input.length) {
224216
$tr.find(inputSelector).prop('checked', $input.prop('checked'));
225217
}
226-
if (_this.$selectAll.length) {
227-
$fixedHeader.add($fixedBody).find('[name="btSelectAll"]').prop('checked', _this.$selectAll.prop('checked'));
218+
if (that.$selectAll.length) {
219+
$fixedHeader.add($fixedBody).find('[name="btSelectAll"]').prop('checked', that.$selectAll.prop('checked'));
228220
}
229221
};
230-
if (_this.$fixedBody && _this.options.fixedNumber) {
231-
updateFixedBody(_this.$fixedHeader, _this.$fixedBody);
222+
if (that.$fixedBody && that.options.fixedNumber) {
223+
updateFixedBody(that.$fixedHeader, that.$fixedBody);
232224
}
233225

234-
if (_this.$fixedBodyRight && _this.options.fixedRightNumber) {
235-
updateFixedBody(_this.$fixedHeaderRight, _this.$fixedBodyRight);
226+
if (that.$fixedBodyRight && that.options.fixedRightNumber) {
227+
updateFixedBody(that.$fixedHeaderRight, that.$fixedBodyRight);
236228
}
237229
});
238230
};
@@ -249,7 +241,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
249241
};
250242

251243
BootstrapTable.prototype.initFixedColumnsHeader = function () {
252-
var _this2 = this;
244+
var that = this;
253245

254246
if (this.options.height) {
255247
this.needFixedColumns = this.$tableHeader.outerWidth(true) < this.$tableHeader.find('table').outerWidth(true);
@@ -259,10 +251,10 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
259251

260252
var initFixedHeader = function initFixedHeader($fixedColumns, isRight) {
261253
$fixedColumns.find('.fixed-table-header').remove();
262-
$fixedColumns.append(_this2.$tableHeader.clone(true));
254+
$fixedColumns.append(that.$tableHeader.clone(true));
263255
$fixedColumns.find('.fixed-table-header').css('margin-right', "");
264256
$fixedColumns.css({
265-
width: _this2.getFixedColumnsWidth(isRight)
257+
width: that.getFixedColumnsWidth(isRight)
266258
});
267259
return $fixedColumns.find('.fixed-table-header');
268260
};
@@ -286,19 +278,19 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
286278
};
287279

288280
BootstrapTable.prototype.initFixedColumnsBody = function () {
289-
var _this3 = this;
281+
var that = this;
290282

291283
var initFixedBody = function initFixedBody($fixedColumns, $fixedHeader) {
292284
$fixedColumns.find('.fixed-table-body').remove();
293-
$fixedColumns.append(_this3.$tableBody.clone(true));
285+
$fixedColumns.append(that.$tableBody.clone(true));
294286

295287
var $fixedBody = $fixedColumns.find('.fixed-table-body');
296288

297-
var tableBody = _this3.$tableBody.get(0);
289+
var tableBody = that.$tableBody.get(0);
298290
var scrollHeight = tableBody.scrollWidth > tableBody.clientWidth ? getScrollBarWidth() : 0;
299291
var paginationHeight = $(".fixed-table-pagination").height();
300-
if (typeof _this3.options.height !== 'undefined') paginationHeight = 0;
301-
var height = _this3.$tableContainer.outerHeight(true) - scrollHeight - paginationHeight + 1;
292+
if (typeof that.options.height !== 'undefined') paginationHeight = 0;
293+
var height = that.$tableContainer.outerHeight(true) - scrollHeight - paginationHeight + 1;
302294
$fixedColumns.css({
303295
height: height
304296
});
@@ -342,17 +334,17 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
342334
};
343335

344336
BootstrapTable.prototype.initFixedColumnsEvents = function () {
345-
var _this4 = this;
337+
var that = this;
346338

347339
var toggleHover = function toggleHover(e, toggle) {
348340
var tr = 'tr[data-index="' + $(e.currentTarget).data('index') + '"]';
349-
var $trs = _this4.$tableBody.find(tr);
341+
var $trs = that.$tableBody.find(tr);
350342

351-
if (_this4.$fixedBody) {
352-
$trs = $trs.add(_this4.$fixedBody.find(tr));
343+
if (that.$fixedBody) {
344+
$trs = $trs.add(that.$fixedBody.find(tr));
353345
}
354-
if (_this4.$fixedBodyRight) {
355-
$trs = $trs.add(_this4.$fixedBodyRight.find(tr));
346+
if (that.$fixedBodyRight) {
347+
$trs = $trs.add(that.$fixedBodyRight.find(tr));
356348
}
357349

358350
$trs.css('background-color', toggle ? $(e.currentTarget).css('background-color') : '');
@@ -367,17 +359,17 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
367359
var updateScroll = function updateScroll(e, fixedBody) {
368360
var normalized = normalizeWheel(e);
369361
var deltaY = Math.ceil(normalized.pixelY);
370-
var top = _this4.$tableBody.scrollTop() + deltaY;
362+
var top = that.$tableBody.scrollTop() + deltaY;
371363
if (deltaY < 0 && top > 0 || deltaY > 0 && top < fixedBody.scrollHeight - fixedBody.clientHeight) {
372364
e.preventDefault();
373365
}
374366

375-
_this4.$tableBody.scrollTop(top);
376-
if (_this4.$fixedBody) {
377-
_this4.$fixedBody.scrollTop(top);
367+
that.$tableBody.scrollTop(top);
368+
if (that.$fixedBody) {
369+
that.$fixedBody.scrollTop(top);
378370
}
379-
if (_this4.$fixedBodyRight) {
380-
_this4.$fixedBodyRight.scrollTop(top);
371+
if (that.$fixedBodyRight) {
372+
that.$fixedBodyRight.scrollTop(top);
381373
}
382374
};
383375
if (this.needFixedColumns && this.options.fixedNumber) {
@@ -388,25 +380,25 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
388380
});
389381
this.$fixedBody[0].addEventListener(mousewheel, function (e) {
390382
//给鼠标滑轮绑定事件
391-
updateScroll(e, _this4.$fixedBody[0]);
383+
updateScroll(e, that.$fixedBody[0]);
392384
});
393385
}
394386
//给原本表格绑定scroll事件
395387
$('div.fixed-table-body').off('scroll'); //给所有的body解绑 scroll
396388
this.$tableBody.off('scroll').on('scroll', function (e) {
397-
_this4.$tableHeader.scrollLeft(0);
398-
if (_this4.$tableBody.scrollLeft() > 0) {
399-
_this4.$tableHeader.scrollLeft(_this4.$tableBody.scrollLeft());
400-
if (_this4.options.showFooter && !_this4.options.cardView) {
401-
_this4.$tableFooter.scrollLeft(_this4.$tableBody.scrollLeft());
389+
that.$tableHeader.scrollLeft(0);
390+
if (that.$tableBody.scrollLeft() > 0) {
391+
that.$tableHeader.scrollLeft(that.$tableBody.scrollLeft());
392+
if (that.options.showFooter && !that.options.cardView) {
393+
that.$tableFooter.scrollLeft(that.$tableBody.scrollLeft());
402394
}
403395
}
404-
var top = _this4.$tableBody.scrollTop();
405-
if (_this4.$fixedBody) {
406-
_this4.$fixedBody.scrollTop(top);
396+
var top = that.$tableBody.scrollTop();
397+
if (that.$fixedBody) {
398+
that.$fixedBody.scrollTop(top);
407399
}
408-
if (_this4.$fixedBodyRight) {
409-
_this4.$fixedBodyRight.scrollTop(top);
400+
if (that.$fixedBodyRight) {
401+
that.$fixedBodyRight.scrollTop(top);
410402
}
411403
});
412404

@@ -418,13 +410,13 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
418410
});
419411
this.$fixedBodyRight[0].addEventListener(mousewheel, function (e) {
420412
//给鼠标滑轮绑定事件
421-
updateScroll(e, _this4.$fixedBodyRight[0]);
413+
updateScroll(e, that.$fixedBodyRight[0]);
422414
});
423415
//给固定表格的checkbox绑定事件
424416
this.$fixedBody && this.$fixedBody.find('input[name="' + this.options.selectItemName + '"]').off("click").on('click', function (e) {
425417
e.stopImmediatePropagation();
426418
var index = $(e.target).data("index");
427-
$(_this4.$selectItem[index]).trigger("click");
419+
$(that.$selectItem[index]).trigger("click");
428420
});
429421
}
430422

@@ -433,7 +425,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
433425
var $target = $(e.target);
434426
var value = $target.val();
435427
var field = $target.parents('th').data('field');
436-
var $coreTh = _this4.$header.find('th[data-field="' + field + '"]');
428+
var $coreTh = that.$header.find('th[data-field="' + field + '"]');
437429

438430
if ($target.is('input')) {
439431
$coreTh.find('input').val(value);
@@ -443,7 +435,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
443435
$select.find('option[value="' + value + '"]').attr('selected', true);
444436
}
445437

446-
_this4.triggerSearch();
438+
that.triggerSearch();
447439
});
448440
}
449441
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "fastadmin-bootstraptable",
33
"description": "An extended Bootstrap table with radio, checkbox, sort, pagination, and other added features. (supports twitter bootstrap v2 and v3).",
4-
"version": "1.11.4",
4+
"version": "1.11.5",
55
"main": "./dist/bootstrap-table.js",
66
"devDependencies": {
77
"cz-conventional-changelog": "^1.1.5",

src/extensions/export/bootstrap-table-export.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@
114114
data = {total: that.options.totalRows};
115115
data[that.options.dataField] = that.getData();
116116

117+
var Table = typeof require === 'function' ? require('table') : null;
117118
selectedData = {total: that.options.totalRows};
118-
selectedData[that.options.dataField] = that.getAllSelections();
119+
selectedData[that.options.dataField] = Table && that.options.maintainSelected ? Table.api.selecteddata(that.$el) : that.getAllSelections();
119120
}
120121

121122
that.load(selectedData);

0 commit comments

Comments
 (0)