/**
* @author zhixin wen <wenzhixin2010@gmail.com>
* @version: v1.0.1
* Modificated 16.08.16 by Aleksej Tokarev (Loecha)
* - Sorting Problem solved
* - Recalculated Size of fixed Columns
*/
/**
* J2eeFAST/adamgogogo 二次修改
*/
(function ($) {
'use strict';
$.extend($.fn.bootstrapTable.defaults, {
fixedColumns: false,
fixedNumber: 1,
rightFixedColumns: false,
rightFixedNumber: 1
});
var BootstrapTable = $.fn.bootstrapTable.Constructor,
_initHeader = BootstrapTable.prototype.initHeader,
_initBody = BootstrapTable.prototype.initBody,
_resetView = BootstrapTable.prototype.resetView;
BootstrapTable.prototype.initFixedColumns = function () {
this.timeoutHeaderColumns_ = 0;
this.timeoutBodyColumns_ = 0;
if(this.options.cardView){
if(this.options.fixedColumns){
if($("#"+this.options.id + "-left-fixed-table-columns")){
$("#"+this.options.id + "-left-fixed-table-columns").hide();
}
if($("#"+this.options.id + "-left-fixed-body-columns")){
$("#"+this.options.id + "-left-fixed-body-columns").hide();
}
}
if(this.options.rightFixedColumns){
if($("#"+this.options.id + "-right-fixed-table-columns")){
$("#"+this.options.id + "-right-fixed-table-columns").hide();
}
}
return;
}
if (this.options.fixedColumns) {
var $leftFixedHeader = this.$tableContainer.find('.left-fixed-table-columns');
if(!$leftFixedHeader.length){
this.$fixedHeader = $([
'<div id="'+this.options.id+'-left-fixed-table-columns" class="left-fixed-table-columns">',
'<table>',
'<thead></thead>',
'</table>',
'</div>'].join(''));
this.$fixedHeader.find('table').attr('class', this.$el.attr('class'));
this.$fixedHeaderColumns = this.$fixedHeader.find('thead');
this.$tableHeader.before(this.$fixedHeader);
this.$fixedBody = $([
'<div id="'+this.options.id+'-left-fixed-body-columns" class="left-fixed-body-columns">',
'<table>',
'<tbody></tbody>',
'</table>',
'</div>'].join(''));
this.$fixedBody.find('table').attr('class', this.$el.attr('class'));
this.$fixedBodyColumns = this.$fixedBody.find('tbody');
this.$tableBody.before(this.$fixedBody);
}
}else{
$("#"+this.options.id + "-left-fixed-table-columns").show();
$("#"+this.options.id + "-left-fixed-body-columns").show();
}
if (this.options.rightFixedColumns) {
var $rightFixedHeader = this.$tableContainer.find('.right-fixed-table-columns');
if(!$rightFixedHeader.length){
this.$rightfixedBody = $([
'<div id="'+this.options.id+'-right-fixed-table-columns" class="right-fixed-table-columns">',
'<table>',
'<thead></thead>',
'<tbody style="background-color: #fff;"></tbody>',
'</table>',
'</div>'].join(''));
this.$rightfixedBody.find('table').attr('class', this.$el.attr('class'));
this.$rightfixedHeaderColumns = this.$rightfixedBody.find('thead');
this.$rightfixedBodyColumns = this.$rightfixedBody.find('tbody');
this.$tableBody.before(this.$rightfixedBody);
if (this.options.fixedColumns && this.options.rightFixedNumber) {
// $('.right-fixed-table-columns').attr('style', 'right:' + _w + 'px;');
}
}else{
$("#"+this.options.id + "-right-fixed-table-columns").show();
}
}
};
BootstrapTable.prototype.initHeader = function () {
_initHeader.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.fixedColumns && !this.options.rightFixedColumns){
return;
}
this.initFixedColumns();
var existCondition = setInterval(() => {
var _w2 = document.querySelector('.right-fixed-table-columns > table').offsetWidth;
if (document.querySelector('.right-fixed-table-columns > table') && _w2) {
if (document.querySelectorAll('.right-fixed-table-columns > table> thead > tr > th').length) {
if (document.querySelector('.right-fixed-table-columns').style.right == _w2) clearInterval(existCondition);
document.querySelector('.right-fixed-table-columns > table > thead').style.backgroundColor = "#fff";
document.querySelector('.right-fixed-table-columns').style.right = _w2 + 'px';
}
} else {
clearInterval(existCondition);
}
}, 1000);
if(this.options.cardView){
return;
}
var $ltr = this.$header.find('tr:eq(0)').clone(true),
that = this,
$rtr = this.$header.find('tr:eq(0)').clone(),
$thisRths = this.$header.find('tr:eq(0)').find('th'),
$lths = $ltr.clone(true).find('th'),
$rths = $rtr.clone().find('th');
$ltr.html('');
$rtr.html('');
//右边列冻结
if (this.options.rightFixedColumns) {
// var $trs = this.$header.find('tr').clone(true); //Fix: Aleksej "clone()" mit "clone(true)" ersetzt
// $trs.each(function () {
// // This causes layout problems:
// //$(this).find('th:gt(' + (that.options.fixedNumber -1) + ')').remove(); // Fix: Aleksej "-1" hinnzugefügt. Denn immer eine Spalte Mehr geblieben ist
// $(this).find('th:gt(' + that.options.fixedNumber + ')').remove();
// });
for (var i = 0; i < this.options.rightFixedNumber; i++) {
$rtr.append($rths.eq($rths.length - this.options.rightFixedNumber + i).clone());
$thisRths.eq($rths.length - this.options.rightFixedNumber + i).children().each(function(){
$(this).css("visibility" ,"hidden");
});
}
this.$rightfixedHeaderColumns.html('').append($rtr);
}
//左边列冻结
if (this.options.fixedColumns) { //left-fixed-table-columns
for (var i = 0; i < this.options.fixedNumber; i++) {
$ltr.append($lths.eq(i).clone(true));
}
this.$fixedHeaderColumns.html('').append($ltr);
this.$selectAll = $ltr.find('[name="btSelectAll"]');
this.$selectAll.on('click', function () {
var checked = $(this).prop('checked');
that.$fixedBodyColumns.find("input[name=btSelectItem]").filter(':enabled').prop('checked', checked);
that.$fixedBodyColumns.find("input[name=btSelectItem]").closest('tr')[checked ? 'addClass' : 'removeClass']('selected');
});
}
};
BootstrapTable.prototype.initBody = function () {
_initBody.apply(this, Array.prototype.slice.apply(arguments));
if (!this.options.fixedColumns && !this.options.rightFixedColumns) {
return;
}
if(this.options.cardView){
return;
}
var that = this;
if (this.options.fixedColumns) {
//页面新增左侧表格内容
this.$fixedBodyColumns.html('');
this.$body.find('> tr[data-index]').each(function () {
var $tr = $(this).clone(true),
$tds = $tr.clone(true).find('td');
$tr.html('');
for (var i = 0; i < that.options.fixedNumber; i++) {
var $ftd = $tds.eq(i).clone(true);
var $select
评论0