Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Numerical string sorting incorrectly handles negative values #6092

Closed
@deisner

Description

@deisner

Describe the bug

When the item data for a column contains strings that represent numerical values, the sorting behavior is as expected, but only if no negative values are included.

Steps to reproduce the bug

  1. Go to https://bootstrap-vue.org/docs/components/table#sorting
  2. In the Live data, change the items to this (note that the age values are strings):
items: [
          { isActive: true, age: "20", first_name: 'Dickerson', last_name: 'Macdonald' },
          { isActive: false, age: "100", first_name: 'Larsen', last_name: 'Shaw' },
          { isActive: false, age: "1", first_name: 'Geneva', last_name: 'Wilson' },
          { isActive: true, age: "-1", first_name: 'Linus', last_name: 'Carney' },
          { isActive: true, age: "-100", first_name: 'Sally', last_name: 'Carney' },
          { isActive: true, age: "-20", first_name: 'Schroeder', last_name: 'Carney' },
        ]
  1. Click the Age table header twice to sort in descending order:

image

  1. The age values, even though strings, are sorted as numbers -- i.e. this is not a dictionary sort (i.e. "20", "100", "1" for a descending sort). But the negative values are in reversed order from what they ought to be.

Expected behavior

The sorted values should be 100, 20, 1, -1, -20, -100, i.e. in decreasing numerical order.

Versions

Libraries:

  • BootstrapVue: 2.19.0
  • Bootstrap: 4.5.3
  • Vue: 2.6.11

Environment:

  • Device: Mac
  • OS: macOS Catalina
  • Browser: Chrome
  • Version: 86.0.4240.198

Additional context

I'm quite happy that the sorting is smart enough to recognize that "100" is a number -- I'd just like it to work correctly with negative numbers, too.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions