Browse Source

Merge branch 'develop' of https://github.com/wenzhixin/bootstrap-table into add-custom-sorter-functionality-to-multiple-sort

jbarrineau06 5 years ago
parent
commit
68c60cb24c

+ 10 - 3
src/bootstrap-table.js

@@ -569,6 +569,13 @@ class BootstrapTable {
           html.push(this.constants.html.toolbarDropdownSeparator)
         }
 
+        let visibleColumns = 0
+        this.columns.forEach((column, i) => {
+          if (column.visible) {
+            visibleColumns++
+          }
+        })
+
         this.columns.forEach((column, i) => {
           if (this.isSelectionColumn(column)) {
             return
@@ -579,11 +586,11 @@ class BootstrapTable {
           }
 
           const checked = column.visible ? ' checked="checked"' : ''
-
+          const disabled = (visibleColumns <= this.options.minimumCountColumns) && checked ? ' disabled="disabled"' : ''
           if (column.switchable) {
             html.push(Utils.sprintf(this.constants.html.toolbarDropdownItem,
-              Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s> <span>%s</span>',
-                column.field, i, checked, column.title)))
+              Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s%s> <span>%s</span>',
+                column.field, i, checked, disabled, column.title)))
             switchableCount++
           }
         })

+ 9 - 0
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -405,6 +405,15 @@ const UtilsFilterControl = {
           return
         }
 
+        const $select = $(currentTarget)
+        const value = $select.val()
+        if ($.trim(value)) {
+          $select.find('option[selected]').removeAttr('selected')
+          $select.find('option[value="' + value + '"]').attr('selected', true)
+        } else {
+          $select.find('option[selected]').removeAttr('selected')
+        }
+
         clearTimeout(currentTarget.timeoutId || 0)
         currentTarget.timeoutId = setTimeout(() => {
           that.onColumnSearch({currentTarget, keyCode})

+ 27 - 0
src/extensions/sticky-header/bootstrap-table-sticky-header.js

@@ -45,6 +45,11 @@ $.BootstrapTable = class extends $.BootstrapTable {
     this.$tableBody.off('scroll').on('scroll', () => this.matchPositionX())
   }
 
+  onColumnSearch ({currentTarget, keyCode}) {
+    super.onColumnSearch({currentTarget, keyCode})
+    this.renderStickyHeader()
+  }
+
   resetView (...args) {
     super.resetView(...args)
 
@@ -53,6 +58,28 @@ $.BootstrapTable = class extends $.BootstrapTable {
   }
 
   renderStickyHeader () {
+    const that = this
+    this.$stickyHeader = this.$header.clone(true, true)
+
+    if (this.options.filterControl) {
+      $(this.$stickyHeader).off('keyup change mouseup').on('keyup change mouse', function (e) {
+        const $target = $(e.target)
+        const value = $target.val()
+        const field = $target.parents('th').data('field')
+        const $coreTh = that.$header.find('th[data-field="' + field + '"]')
+
+        if ($target.is('input')) {
+          $coreTh.find('input').val(value)
+        } else if ($target.is('select')) {
+          const $select = $coreTh.find('select')
+          $select.find('option[selected]').removeAttr('selected')
+          $select.find('option[value="' + value + '"]').attr('selected', true)
+        }
+
+        that.triggerSearch()
+      })
+    }
+
     const top = $(window).scrollTop()
     // top anchor scroll position, minus header height
     const start = this.$stickyBegin.offset().top - this.options.stickyHeaderOffsetY