|
@@ -4,11 +4,37 @@
|
|
|
|
|
|
|
|
$.extend($.fn.bootstrapTable.defaults, {
|
|
$.extend($.fn.bootstrapTable.defaults, {
|
|
|
fixedColumns: false,
|
|
fixedColumns: false,
|
|
|
- fixedNumber: 1
|
|
|
|
|
|
|
+ fixedNumber: 0,
|
|
|
|
|
+ fixedRightNumber: 0
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
$.BootstrapTable = class extends $.BootstrapTable {
|
|
$.BootstrapTable = class extends $.BootstrapTable {
|
|
|
|
|
|
|
|
|
|
+ initContainer () {
|
|
|
|
|
+ if (
|
|
|
|
|
+ this.options.fixedColumns &&
|
|
|
|
|
+ (this.options.fixedNumber || this.options.fixedRightNumber)
|
|
|
|
|
+ ) {
|
|
|
|
|
+ this.options.classes = this.options.classes.replace('table-hover', '')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ super.initContainer()
|
|
|
|
|
+
|
|
|
|
|
+ if (!this.options.fixedColumns) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (this.options.fixedNumber) {
|
|
|
|
|
+ this.$tableContainer.append('<div class="fixed-columns"></div>')
|
|
|
|
|
+ this.$fixedColumns = this.$tableContainer.find('.fixed-columns')
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$tableContainer.append('<div class="fixed-columns-right"></div>')
|
|
|
|
|
+ this.$fixedColumnsRight = this.$tableContainer.find('.fixed-columns-right')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
fitHeader (...args) {
|
|
fitHeader (...args) {
|
|
|
super.fitHeader(...args)
|
|
super.fitHeader(...args)
|
|
|
|
|
|
|
@@ -20,27 +46,30 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.$container.find('.fixed-table-header-columns').remove()
|
|
|
|
|
- this.$fixedHeader = $('<div class="fixed-table-header-columns"></div>')
|
|
|
|
|
- this.$fixedHeader.append(this.$tableHeader.find('>table').clone(true))
|
|
|
|
|
- this.$tableHeader.after(this.$fixedHeader)
|
|
|
|
|
|
|
+ this.needFixedColumns = this.$tableHeader.width() < this.$tableHeader.find('table').width()
|
|
|
|
|
|
|
|
- const width = this.getFixedColumnsWidth()
|
|
|
|
|
|
|
+ if (this.needFixedColumns && this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedColumns.find('.fixed-table-header').remove()
|
|
|
|
|
+ this.$fixedColumns.append(this.$tableHeader.clone(true))
|
|
|
|
|
+ this.$fixedHeader = this.$fixedColumns.find('.fixed-table-header')
|
|
|
|
|
|
|
|
- this.$fixedHeader.css({
|
|
|
|
|
- top: 0,
|
|
|
|
|
- width,
|
|
|
|
|
- height: this.$tableHeader.outerHeight(true)
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ this.$fixedColumns.css({
|
|
|
|
|
+ width: this.getFixedColumnsWidth()
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- this.initFixedColumnsBody()
|
|
|
|
|
|
|
+ if (this.needFixedColumns && this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedColumnsRight.find('.fixed-table-header').remove()
|
|
|
|
|
+ this.$fixedColumnsRight.append(this.$tableHeader.clone(true))
|
|
|
|
|
+ this.$fixedHeaderRight = this.$fixedColumnsRight.find('.fixed-table-header')
|
|
|
|
|
|
|
|
- this.$fixedBody.css({
|
|
|
|
|
- top: this.$tableHeader.outerHeight(true),
|
|
|
|
|
- width,
|
|
|
|
|
- height: this.$tableBody.outerHeight(true) - 1
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ this.$fixedColumnsRight.css({
|
|
|
|
|
+ width: this.getFixedColumnsWidth(true)
|
|
|
|
|
+ })
|
|
|
|
|
+ this.$fixedHeaderRight.scrollLeft(this.$fixedHeaderRight.find('table').width())
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ this.initFixedColumnsBody()
|
|
|
this.initFixedColumnsEvents()
|
|
this.initFixedColumnsEvents()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -56,58 +85,156 @@ $.BootstrapTable = class extends $.BootstrapTable {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.initFixedColumnsBody()
|
|
this.initFixedColumnsBody()
|
|
|
-
|
|
|
|
|
- this.$fixedBody.css({
|
|
|
|
|
- top: 0,
|
|
|
|
|
- width: this.getFixedColumnsWidth(),
|
|
|
|
|
- height: this.$tableHeader.outerHeight(true) + this.$tableBody.outerHeight(true)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
this.initFixedColumnsEvents()
|
|
this.initFixedColumnsEvents()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
initFixedColumnsBody () {
|
|
initFixedColumnsBody () {
|
|
|
- this.$container.find('.fixed-table-body-columns').remove()
|
|
|
|
|
- this.$fixedBody = $('<div class="fixed-table-body-columns"></div>')
|
|
|
|
|
- this.$fixedBody.append(this.$tableBody.find('>table').clone(true))
|
|
|
|
|
- this.$tableBody.after(this.$fixedBody)
|
|
|
|
|
|
|
+ if (this.needFixedColumns && this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedColumns.find('.fixed-table-body').remove()
|
|
|
|
|
+ this.$fixedColumns.append(this.$tableBody.clone(true))
|
|
|
|
|
+ this.$fixedBody = this.$fixedColumns.find('.fixed-table-body')
|
|
|
|
|
+
|
|
|
|
|
+ this.$fixedBody.css({
|
|
|
|
|
+ height: this.$fixedColumns.height() - this.$fixedHeader.height()
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (this.needFixedColumns && this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedColumnsRight.find('.fixed-table-body').remove()
|
|
|
|
|
+ this.$fixedColumnsRight.append(this.$tableBody.clone(true))
|
|
|
|
|
+ this.$fixedBodyRight = this.$fixedColumnsRight.find('.fixed-table-body')
|
|
|
|
|
+
|
|
|
|
|
+ this.$fixedBodyRight.css({
|
|
|
|
|
+ height: this.$fixedColumnsRight.height() - this.$fixedHeaderRight.height()
|
|
|
|
|
+ })
|
|
|
|
|
+ this.$fixedBodyRight.scrollLeft(this.$fixedBodyRight.find('table').width())
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- getFixedColumnsWidth () {
|
|
|
|
|
- const visibleFields = this.getVisibleFields()
|
|
|
|
|
|
|
+ getFixedColumnsWidth (isRight) {
|
|
|
|
|
+ let visibleFields = this.getVisibleFields()
|
|
|
let width = 0
|
|
let width = 0
|
|
|
|
|
+ let fixedNumber = this.options.fixedNumber
|
|
|
|
|
+
|
|
|
|
|
+ if (isRight) {
|
|
|
|
|
+ visibleFields = visibleFields.reverse()
|
|
|
|
|
+ fixedNumber = this.options.fixedRightNumber
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for (let i = 0; i < this.options.fixedNumber; i++) {
|
|
|
|
|
|
|
+ for (let i = 0; i < fixedNumber; i++) {
|
|
|
width += this.$header.find(`th[data-field="${visibleFields[i]}"]`).outerWidth(true)
|
|
width += this.$header.find(`th[data-field="${visibleFields[i]}"]`).outerWidth(true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return width + 1
|
|
return width + 1
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- initFixedColumnsEvents () {
|
|
|
|
|
- // events
|
|
|
|
|
- this.$tableBody.off('scroll.fixed-columns').on('scroll.fixed-columns', e => {
|
|
|
|
|
- this.$fixedBody.find('table').css('top', -$(e.currentTarget).scrollTop())
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ trigger (...args) {
|
|
|
|
|
+ super.trigger(...args)
|
|
|
|
|
|
|
|
- this.$body.find('> tr[data-index]').off('hover').hover(e => {
|
|
|
|
|
- const index = $(e.currentTarget).data('index')
|
|
|
|
|
- this.$fixedBody.find(`tr[data-index="${index}"]`)
|
|
|
|
|
- .css('background-color', $(e.currentTarget).css('background-color'))
|
|
|
|
|
- }, e => {
|
|
|
|
|
- const index = $(e.currentTarget).data('index')
|
|
|
|
|
- const $tr = this.$fixedBody.find(`tr[data-index="${index}"]`)
|
|
|
|
|
- $tr.attr('style', $tr.attr('style').replace(/background-color:.*;/, ''))
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ if (args[0] === 'scroll-body') {
|
|
|
|
|
+ if (this.needFixedColumns && this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedBody.scrollTop(this.$tableBody.scrollTop())
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (this.needFixedColumns && this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedBodyRight.scrollTop(this.$tableBody.scrollTop())
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- this.$fixedBody.find('tr[data-index]').off('hover').hover(e => {
|
|
|
|
|
|
|
+ initFixedColumnsEvents () {
|
|
|
|
|
+ this.$tableBody.find('tr').hover(e => {
|
|
|
const index = $(e.currentTarget).data('index')
|
|
const index = $(e.currentTarget).data('index')
|
|
|
- this.$body.find(`tr[data-index="${index}"]`)
|
|
|
|
|
- .css('background-color', $(e.currentTarget).css('background-color'))
|
|
|
|
|
|
|
+ $(e.currentTarget).addClass('hover')
|
|
|
|
|
+
|
|
|
|
|
+ if (this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedBody.find(`tr[data-index="${index}"]`).addClass('hover')
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedBodyRight.find(`tr[data-index="${index}"]`).addClass('hover')
|
|
|
|
|
+ }
|
|
|
}, e => {
|
|
}, e => {
|
|
|
const index = $(e.currentTarget).data('index')
|
|
const index = $(e.currentTarget).data('index')
|
|
|
- const $tr = this.$body.find(`> tr[data-index="${index}"]`)
|
|
|
|
|
- $tr.attr('style', $tr.attr('style').replace(/background-color:.*;/, ''))
|
|
|
|
|
|
|
+ $(e.currentTarget).removeClass('hover')
|
|
|
|
|
+
|
|
|
|
|
+ if (this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedBody.find(`tr[data-index="${index}"]`).removeClass('hover')
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedBodyRight.find(`tr[data-index="${index}"]`).removeClass('hover')
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ if (this.needFixedColumns && this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedBody.off('mousewheel').on('mousewheel', e => {
|
|
|
|
|
+ const deltaY = e.originalEvent.wheelDeltaY
|
|
|
|
|
+ const top = this.$tableBody.scrollTop() - deltaY
|
|
|
|
|
+ const fixedBody = this.$fixedBody[0]
|
|
|
|
|
+
|
|
|
|
|
+ if (
|
|
|
|
|
+ deltaY > 0 && top > 0 ||
|
|
|
|
|
+ deltaY < 0 && top < fixedBody.scrollHeight - fixedBody.clientHeight
|
|
|
|
|
+ ) {
|
|
|
|
|
+ e.preventDefault()
|
|
|
|
|
+ }
|
|
|
|
|
+ this.$fixedBody.scrollTop(top)
|
|
|
|
|
+ this.$tableBody.scrollTop(top)
|
|
|
|
|
+ if (this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedBodyRight.scrollTop(top)
|
|
|
|
|
+ }
|
|
|
|
|
+ }).find('tr').hover(e => {
|
|
|
|
|
+ const index = $(e.currentTarget).data('index')
|
|
|
|
|
+ $(e.currentTarget).addClass('hover')
|
|
|
|
|
+
|
|
|
|
|
+ this.$tableBody.find(`tr[data-index="${index}"]`).addClass('hover')
|
|
|
|
|
+ if (this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedBodyRight.find(`tr[data-index="${index}"]`).addClass('hover')
|
|
|
|
|
+ }
|
|
|
|
|
+ }, e => {
|
|
|
|
|
+ const index = $(e.currentTarget).data('index')
|
|
|
|
|
+ $(e.currentTarget).removeClass('hover')
|
|
|
|
|
+
|
|
|
|
|
+ this.$tableBody.find(`tr[data-index="${index}"]`).removeClass('hover')
|
|
|
|
|
+ if (this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedBodyRight.find(`tr[data-index="${index}"]`).removeClass('hover')
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (this.needFixedColumns && this.options.fixedRightNumber) {
|
|
|
|
|
+ this.$fixedBodyRight.off('mousewheel').on('mousewheel', e => {
|
|
|
|
|
+ const deltaY = e.originalEvent.wheelDeltaY
|
|
|
|
|
+ const top = this.$tableBody.scrollTop() - deltaY
|
|
|
|
|
+ const fixedBody = this.$fixedBodyRight[0]
|
|
|
|
|
+
|
|
|
|
|
+ if (
|
|
|
|
|
+ deltaY > 0 && top > 0 ||
|
|
|
|
|
+ deltaY < 0 && top < fixedBody.scrollHeight - fixedBody.clientHeight
|
|
|
|
|
+ ) {
|
|
|
|
|
+ e.preventDefault()
|
|
|
|
|
+ }
|
|
|
|
|
+ this.$fixedBodyRight.scrollTop(top)
|
|
|
|
|
+ this.$tableBody.scrollTop(top)
|
|
|
|
|
+ if (this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedBody.scrollTop(top)
|
|
|
|
|
+ }
|
|
|
|
|
+ }).find('tr').hover(e => {
|
|
|
|
|
+ const index = $(e.currentTarget).data('index')
|
|
|
|
|
+ $(e.currentTarget).addClass('hover')
|
|
|
|
|
+
|
|
|
|
|
+ this.$tableBody.find(`tr[data-index="${index}"]`).addClass('hover')
|
|
|
|
|
+ if (this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedBody.find(`tr[data-index="${index}"]`).addClass('hover')
|
|
|
|
|
+ }
|
|
|
|
|
+ }, e => {
|
|
|
|
|
+ const index = $(e.currentTarget).data('index')
|
|
|
|
|
+ $(e.currentTarget).removeClass('hover')
|
|
|
|
|
+
|
|
|
|
|
+ this.$tableBody.find(`tr[data-index="${index}"]`).removeClass('hover')
|
|
|
|
|
+ if (this.options.fixedNumber) {
|
|
|
|
|
+ this.$fixedBody.find(`tr[data-index="${index}"]`).removeClass('hover')
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|