Skip to content

Commit 46360a7

Browse files
authored
fix(b-table): fix sorting for negative numeric string (#7134)
1 parent fd586c0 commit 46360a7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/components/table/helpers/default-sort-compare.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,18 @@ describe('table/helpers/default-sort-compare', () => {
109109
expect(defaultSortCompare(x, w, optionsNullLast)).toBe(-1)
110110
expect(defaultSortCompare(w, x, optionsNullLast)).toBe(1)
111111
})
112+
113+
it('sorts numeric string correctly', async () => {
114+
const options = { sortBy: 'a', numeric: true }
115+
expect(defaultSortCompare({ a: '1' }, { a: '2' }, options)).toBe(-1)
116+
expect(defaultSortCompare({ a: '2' }, { a: '1' }, options)).toBe(1)
117+
expect(defaultSortCompare({ a: '1' }, { a: '1' }, options)).toBe(0)
118+
expect(defaultSortCompare({ a: '-1' }, { a: '1' }, options)).toBe(-1)
119+
expect(defaultSortCompare({ a: '1' }, { a: '-1' }, options)).toBe(1)
120+
expect(defaultSortCompare({ a: '0' }, { a: '0' }, options)).toBe(0)
121+
expect(defaultSortCompare({ a: '1.234' }, { a: '1.567' }, options)).toBe(-1)
122+
expect(defaultSortCompare({ a: '1.561' }, { a: '1.234' }, options)).toBe(1)
123+
expect(defaultSortCompare({ a: '-10' }, { a: '-100' }, options)).toBe(1)
124+
expect(defaultSortCompare({ a: '-20' }, { a: '-30' }, options)).toBe(1)
125+
})
112126
})

src/constants/regex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const RX_HASH_ID = /^#[A-Za-z]+[\w\-:.]*$/
99
export const RX_HTML_TAGS = /(<([^>]+)>)/gi
1010
export const RX_HYPHENATE = /\B([A-Z])/g
1111
export const RX_LOWER_UPPER = /([a-z])([A-Z])/g
12-
export const RX_NUMBER = /^[0-9]*\.?[0-9]+$/
12+
export const RX_NUMBER = /^[-]?[0-9]*\.?[0-9]+$/
1313
export const RX_PLUS = /\+/g
1414
export const RX_REGEXP_REPLACE = /[-/\\^$*+?.()|[\]{}]/g
1515
export const RX_SPACES = /[\s\uFEFF\xA0]+/g

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy