Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(b-table): fix sorting for negative numeric string #7134

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/components/table/helpers/default-sort-compare.spec.js
Expand Up @@ -109,4 +109,18 @@ describe('table/helpers/default-sort-compare', () => {
expect(defaultSortCompare(x, w, optionsNullLast)).toBe(-1)
expect(defaultSortCompare(w, x, optionsNullLast)).toBe(1)
})

it('sorts numeric string correctly', async () => {
const options = { sortBy: 'a', numeric: true }
expect(defaultSortCompare({ a: '1' }, { a: '2' }, options)).toBe(-1)
expect(defaultSortCompare({ a: '2' }, { a: '1' }, options)).toBe(1)
expect(defaultSortCompare({ a: '1' }, { a: '1' }, options)).toBe(0)
expect(defaultSortCompare({ a: '-1' }, { a: '1' }, options)).toBe(-1)
expect(defaultSortCompare({ a: '1' }, { a: '-1' }, options)).toBe(1)
expect(defaultSortCompare({ a: '0' }, { a: '0' }, options)).toBe(0)
expect(defaultSortCompare({ a: '1.234' }, { a: '1.567' }, options)).toBe(-1)
expect(defaultSortCompare({ a: '1.561' }, { a: '1.234' }, options)).toBe(1)
expect(defaultSortCompare({ a: '-10' }, { a: '-100' }, options)).toBe(1)
expect(defaultSortCompare({ a: '-20' }, { a: '-30' }, options)).toBe(1)
})
})
2 changes: 1 addition & 1 deletion src/constants/regex.js
Expand Up @@ -9,7 +9,7 @@ export const RX_HASH_ID = /^#[A-Za-z]+[\w\-:.]*$/
export const RX_HTML_TAGS = /(<([^>]+)>)/gi
export const RX_HYPHENATE = /\B([A-Z])/g
export const RX_LOWER_UPPER = /([a-z])([A-Z])/g
export const RX_NUMBER = /^[0-9]*\.?[0-9]+$/
export const RX_NUMBER = /^[-]?[0-9]*\.?[0-9]+$/
export const RX_PLUS = /\+/g
export const RX_REGEXP_REPLACE = /[-/\\^$*+?.()|[\]{}]/g
export const RX_SPACES = /[\s\uFEFF\xA0]+/g
Expand Down