Skip to content

Commit 35b42a0

Browse files
author
Egor Trutnev
committed
fix
1 parent 1a8975f commit 35b42a0

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/bootstrap-table.js

+13-18
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ class BootstrapTable {
487487
const order = this.options.sortOrder === 'desc' ? -1 : 1
488488
const index = this.header.fields.indexOf(this.options.sortName)
489489
let timeoutId = 0
490-
491490
if (index !== -1) {
492491
if (this.options.sortStable) {
493492
this.data.forEach((row, i) => {
@@ -496,7 +495,6 @@ class BootstrapTable {
496495
}
497496
})
498497
}
499-
500498
if (this.options.customSort) {
501499
Utils.calculateObjectValue(this.options, this.options.customSort, [
502500
this.options.sortName,
@@ -505,22 +503,19 @@ class BootstrapTable {
505503
])
506504
} else if (this.options.groupBy === true && this.options.groupByField !== '') {
507505
const groupedData = {}
508-
509-
this.data.forEach(item => {
510-
const groupKey = Utils.getItemField(item, this.options.groupByField, this.options.escape);
511-
if (!groupedData[groupKey]) {
512-
groupedData[groupKey] = []
513-
}
514-
groupedData[groupKey].push(item)
515-
});
516-
517-
const sortedGroups = Object.keys(groupedData).map(groupKey => {
518-
const group = groupedData[groupKey]
519-
Utils.sort(name, order, index, group, this.header, this.options)
520-
return group
521-
});
522-
523-
this.data = [].concat(...sortedGroups)
506+
this.data.forEach(item => {
507+
const groupKey = Utils.getItemField(item, this.options.groupByField, this.options.escape);
508+
if (!groupedData[groupKey]) {
509+
groupedData[groupKey] = []
510+
}
511+
groupedData[groupKey].push(item)
512+
});
513+
const sortedGroups = Object.keys(groupedData).map(groupKey => {
514+
const group = groupedData[groupKey]
515+
Utils.sort(name, order, index, group, this.header, this.options)
516+
return group
517+
});
518+
this.data = [].concat(...sortedGroups)
524519
} else {
525520
Utils.sort(name, order, index, this.data, this.header, this.options)
526521
}

src/utils/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -514,15 +514,15 @@ export default {
514514
return data
515515
},
516516

517-
sort(name, order, index, data, header, options) {
517+
sort (name, order, index, data, header, options) {
518518
data.sort((a, b) => {
519519
if (header.sortNames[index]) {
520520
name = header.sortNames[index]
521521
}
522522

523-
const aa = Utils.getItemField(a, name, options.escape)
524-
const bb = Utils.getItemField(b, name, options.escape)
525-
const value = Utils.calculateObjectValue(header, header.sorters[index], [aa, bb, a, b])
523+
let aa = getItemField(a, name, options.escape)
524+
let bb = getItemField(b, name, options.escape)
525+
const value = calculateObjectValue(header, header.sorters[index], [aa, bb, a, b])
526526

527527
if (value !== undefined) {
528528
if (options.sortStable && value === 0) {
@@ -539,8 +539,8 @@ export default {
539539
}
540540

541541
if (options.sortStable && aa === bb) {
542-
aa = aPosition
543-
bb = bPosition
542+
aa = a._position
543+
bb = b._position
544544
}
545545

546546
// If both values are numeric, do a numeric comparison
@@ -580,7 +580,7 @@ export default {
580580
}
581581

582582
return order
583-
});
583+
})
584584
},
585585

586586
getEventName (eventPrefix, id = '') {

0 commit comments

Comments
 (0)