|
|
@@ -8,6 +8,7 @@ import Constants from './constants/index.js'
|
|
|
import Utils from './utils/index.js'
|
|
|
import VirtualScroll from './virtual-scroll/index.js'
|
|
|
import {isNumeric, isEmptyObject} from './types.js'
|
|
|
+import Sort from './sort.js'
|
|
|
|
|
|
class BootstrapTable {
|
|
|
constructor (el, options) {
|
|
|
@@ -401,8 +402,8 @@ class BootstrapTable {
|
|
|
if (this.header.sortNames[index]) {
|
|
|
name = this.header.sortNames[index]
|
|
|
}
|
|
|
- let aa = Utils.getItemField(a, name, this.options.escape)
|
|
|
- let bb = Utils.getItemField(b, name, this.options.escape)
|
|
|
+ const aa = Utils.getItemField(a, name, this.options.escape)
|
|
|
+ const bb = Utils.getItemField(b, name, this.options.escape)
|
|
|
const value = Utils.calculateObjectValue(this.header, this.header.sorters[index], [aa, bb, a, b])
|
|
|
|
|
|
if (value !== undefined) {
|
|
|
@@ -412,47 +413,7 @@ class BootstrapTable {
|
|
|
return order * value
|
|
|
}
|
|
|
|
|
|
- // Fix #161: undefined or null string sort bug.
|
|
|
- if (aa === undefined || aa === null) {
|
|
|
- aa = ''
|
|
|
- }
|
|
|
- if (bb === undefined || bb === null) {
|
|
|
- bb = ''
|
|
|
- }
|
|
|
-
|
|
|
- if (this.options.sortStable && aa === bb) {
|
|
|
- aa = a._position
|
|
|
- bb = b._position
|
|
|
- }
|
|
|
-
|
|
|
- // IF both values are numeric, do a numeric comparison
|
|
|
- if (isNumeric(aa) && isNumeric(bb)) {
|
|
|
- // Convert numerical values form string to float.
|
|
|
- aa = parseFloat(aa)
|
|
|
- bb = parseFloat(bb)
|
|
|
- if (aa < bb) {
|
|
|
- return order * -1
|
|
|
- }
|
|
|
- if (aa > bb) {
|
|
|
- return order
|
|
|
- }
|
|
|
- return 0
|
|
|
- }
|
|
|
-
|
|
|
- if (aa === bb) {
|
|
|
- return 0
|
|
|
- }
|
|
|
-
|
|
|
- // If value is not a string, convert to string
|
|
|
- if (typeof aa !== 'string') {
|
|
|
- aa = aa.toString()
|
|
|
- }
|
|
|
-
|
|
|
- if (aa.localeCompare(bb) === -1) {
|
|
|
- return order * -1
|
|
|
- }
|
|
|
-
|
|
|
- return order
|
|
|
+ return Sort(aa, bb, order, this.options.sortStable)
|
|
|
})
|
|
|
}
|
|
|
|