mirror of https://gitee.com/y_project/RuoYi.git
新增支持冻结列
parent
25d7c2c1f7
commit
170e736c44
|
@ -0,0 +1,27 @@
|
||||||
|
.fixed-table-header-columns,
|
||||||
|
.fixed-table-body-columns {
|
||||||
|
position: absolute;
|
||||||
|
background-color: #fff;
|
||||||
|
display: none;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed-table-header-columns .table,
|
||||||
|
.fixed-table-body-columns .table {
|
||||||
|
border-right: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed-table-header-columns .table.table-no-bordered,
|
||||||
|
.fixed-table-body-columns .table.table-no-bordered {
|
||||||
|
border-right: 1px solid transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fixed-table-body-columns table {
|
||||||
|
position: absolute;
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bootstrap-table .table-hover > tbody > tr.hover > td{
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
|
@ -0,0 +1,176 @@
|
||||||
|
/**
|
||||||
|
* @author zhixin wen <wenzhixin2010@gmail.com>
|
||||||
|
* @version: v1.0.1
|
||||||
|
*/
|
||||||
|
(function ($) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
$.extend($.fn.bootstrapTable.defaults, {
|
||||||
|
fixedColumns: false,
|
||||||
|
fixedNumber: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
||||||
|
_initHeader = BootstrapTable.prototype.initHeader,
|
||||||
|
_initBody = BootstrapTable.prototype.initBody,
|
||||||
|
_resetView = BootstrapTable.prototype.resetView;
|
||||||
|
|
||||||
|
BootstrapTable.prototype.initFixedColumns = function () {
|
||||||
|
this.$fixedHeader = $([
|
||||||
|
'<div class="fixed-table-header-columns">',
|
||||||
|
'<table>',
|
||||||
|
'<thead></thead>',
|
||||||
|
'</table>',
|
||||||
|
'</div>'].join(''));
|
||||||
|
|
||||||
|
this.timeoutHeaderColumns_ = 0;
|
||||||
|
this.$fixedHeader.find('table').attr('class', this.$el.attr('class'));
|
||||||
|
this.$fixedHeaderColumns = this.$fixedHeader.find('thead');
|
||||||
|
this.$tableHeader.before(this.$fixedHeader);
|
||||||
|
|
||||||
|
this.$fixedBody = $([
|
||||||
|
'<div class="fixed-table-body-columns">',
|
||||||
|
'<table>',
|
||||||
|
'<tbody></tbody>',
|
||||||
|
'</table>',
|
||||||
|
'</div>'].join(''));
|
||||||
|
|
||||||
|
this.timeoutBodyColumns_ = 0;
|
||||||
|
this.$fixedBody.find('table').attr('class', this.$el.attr('class'));
|
||||||
|
this.$fixedBodyColumns = this.$fixedBody.find('tbody');
|
||||||
|
this.$tableBody.before(this.$fixedBody);
|
||||||
|
};
|
||||||
|
|
||||||
|
BootstrapTable.prototype.initHeader = function () {
|
||||||
|
_initHeader.apply(this, Array.prototype.slice.apply(arguments));
|
||||||
|
|
||||||
|
if (!this.options.fixedColumns) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.initFixedColumns();
|
||||||
|
|
||||||
|
var that = this, $trs = this.$header.find('tr').clone();
|
||||||
|
$trs.each(function () {
|
||||||
|
$(this).find('th:gt(' + that.options.fixedNumber + ')').remove();
|
||||||
|
});
|
||||||
|
this.$fixedHeaderColumns.html('').append($trs);
|
||||||
|
};
|
||||||
|
|
||||||
|
BootstrapTable.prototype.initBody = function () {
|
||||||
|
_initBody.apply(this, Array.prototype.slice.apply(arguments));
|
||||||
|
|
||||||
|
if (!this.options.fixedColumns) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var that = this,
|
||||||
|
rowspan = 0;
|
||||||
|
|
||||||
|
this.$fixedBodyColumns.html('');
|
||||||
|
this.$body.find('> tr[data-index]').each(function () {
|
||||||
|
var $tr = $(this).clone(),
|
||||||
|
$tds = $tr.find('td');
|
||||||
|
|
||||||
|
$tr.html('');
|
||||||
|
var end = that.options.fixedNumber;
|
||||||
|
if (rowspan > 0) {
|
||||||
|
--end;
|
||||||
|
--rowspan;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < end; i++) {
|
||||||
|
$tr.append($tds.eq(i).clone());
|
||||||
|
}
|
||||||
|
that.$fixedBodyColumns.append($tr);
|
||||||
|
|
||||||
|
if ($tds.eq(0).attr('rowspan')){
|
||||||
|
rowspan = $tds.eq(0).attr('rowspan') - 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
BootstrapTable.prototype.resetView = function () {
|
||||||
|
_resetView.apply(this, Array.prototype.slice.apply(arguments));
|
||||||
|
|
||||||
|
if (!this.options.fixedColumns) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTimeout(this.timeoutHeaderColumns_);
|
||||||
|
this.timeoutHeaderColumns_ = setTimeout($.proxy(this.fitHeaderColumns, this), this.$el.is(':hidden') ? 100 : 0);
|
||||||
|
|
||||||
|
clearTimeout(this.timeoutBodyColumns_);
|
||||||
|
this.timeoutBodyColumns_ = setTimeout($.proxy(this.fitBodyColumns, this), this.$el.is(':hidden') ? 100 : 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
BootstrapTable.prototype.fitHeaderColumns = function () {
|
||||||
|
var that = this,
|
||||||
|
visibleFields = this.getVisibleFields(),
|
||||||
|
headerWidth = 0;
|
||||||
|
|
||||||
|
this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
|
||||||
|
var $this = $(this),
|
||||||
|
index = i;
|
||||||
|
|
||||||
|
if (i >= that.options.fixedNumber) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (that.options.detailView && !that.options.cardView) {
|
||||||
|
index = i - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
that.$fixedHeader.find('th[data-field="' + visibleFields[index] + '"]')
|
||||||
|
.find('.fht-cell').width($this.innerWidth());
|
||||||
|
headerWidth += $this.outerWidth();
|
||||||
|
});
|
||||||
|
this.$fixedHeader.width(headerWidth + 1).show();
|
||||||
|
};
|
||||||
|
|
||||||
|
BootstrapTable.prototype.fitBodyColumns = function () {
|
||||||
|
var that = this,
|
||||||
|
top = -(parseInt(this.$el.css('margin-top')) - 2),
|
||||||
|
// the fixed height should reduce the scorll-x height
|
||||||
|
height = this.$tableBody.height() - 14;
|
||||||
|
|
||||||
|
if (!this.$body.find('> tr[data-index]').length) {
|
||||||
|
this.$fixedBody.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.options.height) {
|
||||||
|
top = this.$fixedHeader.height();
|
||||||
|
height = height - top;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$fixedBody.css({
|
||||||
|
width: this.$fixedHeader.width(),
|
||||||
|
height: height,
|
||||||
|
top: top
|
||||||
|
}).show();
|
||||||
|
|
||||||
|
this.$body.find('> tr').each(function (i) {
|
||||||
|
that.$fixedBody.find('tr:eq(' + i + ')').height($(this).height() - 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
// events
|
||||||
|
this.$tableBody.on('scroll', function () {
|
||||||
|
that.$fixedBody.find('table').css('top', -$(this).scrollTop());
|
||||||
|
});
|
||||||
|
this.$body.find('> tr[data-index]').off('hover').hover(function () {
|
||||||
|
var index = $(this).data('index');
|
||||||
|
that.$fixedBody.find('tr[data-index="' + index + '"]').addClass('hover');
|
||||||
|
}, function () {
|
||||||
|
var index = $(this).data('index');
|
||||||
|
that.$fixedBody.find('tr[data-index="' + index + '"]').removeClass('hover');
|
||||||
|
});
|
||||||
|
this.$fixedBody.find('tr[data-index]').off('hover').hover(function () {
|
||||||
|
var index = $(this).data('index');
|
||||||
|
that.$body.find('tr[data-index="' + index + '"]').addClass('hover');
|
||||||
|
}, function () {
|
||||||
|
var index = $(this).data('index');
|
||||||
|
that.$body.find('> tr[data-index="' + index + '"]').removeClass('hover');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
})(jQuery);
|
|
@ -19,6 +19,8 @@
|
||||||
_striped = $.common.isEmpty(options.striped) ? false : options.striped;
|
_striped = $.common.isEmpty(options.striped) ? false : options.striped;
|
||||||
_escape = $.common.isEmpty(options.escape) ? false : options.escape;
|
_escape = $.common.isEmpty(options.escape) ? false : options.escape;
|
||||||
_showFooter = $.common.isEmpty(options.showFooter) ? false : options.showFooter;
|
_showFooter = $.common.isEmpty(options.showFooter) ? false : options.showFooter;
|
||||||
|
_fixedColumns = $.common.isEmpty(options.fixedColumns) ? false : options.fixedColumns;
|
||||||
|
_fixedNumber = $.common.isEmpty(options.fixedNumber) ? 0 : options.fixedNumber;
|
||||||
$('#bootstrap-table').bootstrapTable({
|
$('#bootstrap-table').bootstrapTable({
|
||||||
url: options.url, // 请求后台的URL(*)
|
url: options.url, // 请求后台的URL(*)
|
||||||
contentType: "application/x-www-form-urlencoded", // 编码类型
|
contentType: "application/x-www-form-urlencoded", // 编码类型
|
||||||
|
@ -44,6 +46,8 @@
|
||||||
showColumns: $.common.visible(options.showColumns), // 是否显示隐藏某列下拉框
|
showColumns: $.common.visible(options.showColumns), // 是否显示隐藏某列下拉框
|
||||||
showToggle: $.common.visible(options.showToggle), // 是否显示详细视图和列表视图的切换按钮
|
showToggle: $.common.visible(options.showToggle), // 是否显示详细视图和列表视图的切换按钮
|
||||||
showExport: $.common.visible(options.showExport), // 是否支持导出文件
|
showExport: $.common.visible(options.showExport), // 是否支持导出文件
|
||||||
|
fixedColumns: _fixedColumns, // 是否启用冻结列
|
||||||
|
fixedNumber: _fixedNumber, // 冻结列的个数
|
||||||
queryParams: $.table._params, // 传递参数(*)
|
queryParams: $.table._params, // 传递参数(*)
|
||||||
columns: options.columns, // 显示列信息(*)
|
columns: options.columns, // 显示列信息(*)
|
||||||
responseHandler: $.table.responseHandler // 回调函数
|
responseHandler: $.table.responseHandler // 回调函数
|
||||||
|
@ -140,6 +144,7 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var index = layer.load(2, {shade: false});
|
var index = layer.load(2, {shade: false});
|
||||||
|
$.modal.disable();
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append("file", $('#file')[0].files[0]);
|
formData.append("file", $('#file')[0].files[0]);
|
||||||
formData.append("updateSupport", $("input[name='updateSupport']").is(':checked'));
|
formData.append("updateSupport", $("input[name='updateSupport']").is(':checked'));
|
||||||
|
@ -157,6 +162,7 @@
|
||||||
$.table.refresh();
|
$.table.refresh();
|
||||||
} else {
|
} else {
|
||||||
layer.close(index);
|
layer.close(index);
|
||||||
|
$.modal.enable();
|
||||||
$.modal.alertError(result.msg);
|
$.modal.alertError(result.msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -469,11 +475,13 @@
|
||||||
},
|
},
|
||||||
// 禁用按钮
|
// 禁用按钮
|
||||||
disable: function() {
|
disable: function() {
|
||||||
$("a[class*=layui-layer-btn]", window.parent.document).addClass("layer-disabled");
|
var doc = window.top == window.parent ? window.document : window.parent.document;
|
||||||
|
$("a[class*=layui-layer-btn]", doc).addClass("layer-disabled");
|
||||||
},
|
},
|
||||||
// 启用按钮
|
// 启用按钮
|
||||||
enable: function() {
|
enable: function() {
|
||||||
$("a[class*=layui-layer-btn]", window.parent.document).removeClass("layer-disabled");
|
var doc = window.top == window.parent ? window.document : window.parent.document;
|
||||||
|
$("a[class*=layui-layer-btn]", doc).removeClass("layer-disabled");
|
||||||
},
|
},
|
||||||
// 打开遮罩层
|
// 打开遮罩层
|
||||||
loading: function (message) {
|
loading: function (message) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<!-- bootstrap-table 表格插件样式 -->
|
<!-- bootstrap-table 表格插件样式 -->
|
||||||
<link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
|
<link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
|
||||||
<link th:href="@{/ajax/libs/bootstrap-treetable/bootstrap-treetable.css}" rel="stylesheet"/>
|
<link th:href="@{/ajax/libs/bootstrap-treetable/bootstrap-treetable.css}" rel="stylesheet"/>
|
||||||
|
<link th:href="@{/ajax/libs/bootstrap-table/extensions/columns/bootstrap-table-fixed-columns.css}" rel="stylesheet"/>
|
||||||
<link th:href="@{/css/animate.css}" rel="stylesheet"/>
|
<link th:href="@{/css/animate.css}" rel="stylesheet"/>
|
||||||
<link th:href="@{/css/style.css}" rel="stylesheet"/>
|
<link th:href="@{/css/style.css}" rel="stylesheet"/>
|
||||||
<link th:href="@{/ajax/libs/select/select2.css}" rel="stylesheet"/>
|
<link th:href="@{/ajax/libs/select/select2.css}" rel="stylesheet"/>
|
||||||
|
@ -24,6 +25,7 @@
|
||||||
<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
|
<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
|
||||||
<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js}"></script>
|
<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js}"></script>
|
||||||
<script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
|
<script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
|
||||||
|
<script th:src="@{/ajax/libs/bootstrap-table/extensions/columns/bootstrap-table-fixed-columns.js}"></script>
|
||||||
<!-- jquery-validate 表单验证插件 -->
|
<!-- jquery-validate 表单验证插件 -->
|
||||||
<script th:src="@{/ajax/libs/validate/jquery.validate.min.js}"></script>
|
<script th:src="@{/ajax/libs/validate/jquery.validate.min.js}"></script>
|
||||||
<script th:src="@{/ajax/libs/validate/messages_zh.min.js}"></script>
|
<script th:src="@{/ajax/libs/validate/messages_zh.min.js}"></script>
|
||||||
|
|
Loading…
Reference in New Issue