refactor: 动态计算数据表格高度

This commit is contained in:
Argo Zhang 2020-01-18 18:21:07 +08:00
parent cae1be17c6
commit 38c0b41433
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
1 changed files with 19 additions and 4 deletions

View File

@ -438,16 +438,31 @@
// 判断是否固定表头
var fixHeader = this.attr('data-fixedHeader') === '';
var $tabContainer = $(settings.tableContainer);
var $table = this;
if (fixHeader && settings.height === undefined) {
if (settings.calcHeight === undefined) {
settings.calcHeight = function () {
var marginHeight = 0;
if ($tabContainer.length === 1) {
marginHeight = $tabContainer.outerHeight() - $tabContainer.height();
}
marginHeight = ($tabContainer.outerHeight() - $tabContainer.height()) * 2;
// 38: card-header
return Math.max(settings.minHeight, $(window).height() - $('header').height() - $('footer').height() - (marginHeight * 2) - 38 - 32 - 10);
// 计算 table 控件前组件高度
var $prev = $table.prev();
while ($prev.length == 1) {
marginHeight += $prev.outerHeight(true);
$prev = $prev.prev();
}
// 计算 Card Header 高度
if ($table.parent().hasClass('card-body')) {
// 判断 card-header 是否显示并计算高度
var $cardHader = $table.parent().prev();
if ($cardHader.is(":visible")) {
marginHeight += $cardHader.outerHeight(true);
}
}
}
return Math.max(settings.minHeight, $(window).height() - $('header').outerHeight(true) - $('footer').outerHeight(true) - marginHeight - 15 - 10);
};
}