Skip to content

Commit be14412

Browse files
authored
Merge pull request #8292 from wenzhixin/feature/fix-filter-control-select-and-sticky-header-crash
Fix filter-control select option loss and sticky-header undefined crash
2 parents 7caa038 + 3ba8a80 commit be14412

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/extensions/filter-control/utils.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -474,18 +474,11 @@ export function createControls (that, header) {
474474
const $selectControl = $(currentTarget)
475475
const value = $selectControl.val()
476476

477-
if (Array.isArray(value)) {
478-
for (let i = 0; i < value.length; i++) {
479-
if (value[i] && value[i].length > 0 && value[i].trim()) {
480-
$selectControl.find(`option[value="${value[i]}"]`).attr('selected', true)
481-
}
482-
}
483-
} else if (value && value.length > 0 && value.trim()) {
484-
$selectControl.find('option[selected]').removeAttr('selected')
485-
$selectControl.find(`option[value="${value}"]`).attr('selected', true)
486-
} else {
487-
$selectControl.find('option[selected]').removeAttr('selected')
488-
}
477+
const normalizedValue = value === null ?
478+
$selectControl.prop('multiple') ? [] : null :
479+
value
480+
481+
$selectControl.val(normalizedValue)
489482

490483
clearTimeout(currentTarget.timeoutId || 0)
491484
currentTarget.timeoutId = setTimeout(() => {

src/extensions/sticky-header/bootstrap-table-sticky-header.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ $.BootstrapTable = class extends $.BootstrapTable {
8989
renderStickyHeader () {
9090
const that = this
9191

92+
if (
93+
!this.$stickyContainer || !this.$stickyContainer.length ||
94+
!this.$stickyBegin || !this.$stickyBegin.length ||
95+
!this.$stickyEnd || !this.$stickyEnd.length
96+
) {
97+
return
98+
}
99+
92100
this.$stickyHeader = this.$header.clone(true, true)
93101

94102
if (this.options.filterControl) {
@@ -103,8 +111,11 @@ $.BootstrapTable = class extends $.BootstrapTable {
103111
} else if ($target.is('select')) {
104112
const $select = $coreTh.find('select')
105113

106-
$select.find('option[selected]').removeAttr('selected')
107-
$select.find(`option[value="${value}"]`).attr('selected', true)
114+
const normalizedValue = value === null ?
115+
$select.prop('multiple') ? [] : null :
116+
value
117+
118+
$select.val(normalizedValue)
108119
}
109120

110121
that.triggerSearch()

0 commit comments

Comments
 (0)