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

[Component] [table] Sortable El-Table #16618

Open
leeobrum opened this issue Apr 22, 2024 · 4 comments
Open

[Component] [table] Sortable El-Table #16618

leeobrum opened this issue Apr 22, 2024 · 4 comments

Comments

@leeobrum
Copy link

Bug Type: Component

Environment

  • Vue Version: 3.4.24
  • Element Plus Version: 2.7.1
  • Browser / OS: Edge
  • Build Tool: Vite

Reproduction

Related Component

  • el-table

Reproduction Link

Element Plus Playground

Steps to reproduce

use sortable

What is Expected?

order correctly

What is actually happening?

The function is ordering wrong

Additional comments

Maybe I don't know how to do it, but I wasted some time on this and couldn't solve it.

@zeyongTsai
Copy link
Contributor

The comparison of magnitude between strings is different from numbers. If you expect numerical magnitude ordering, please convert them to numbers before making the comparison.

@leeobrum
Copy link
Author

leeobrum commented Apr 23, 2024

@zeyongTsai I understood
but, I will show numbers in the field and I will need to show string when the field is empty, that's the problem.

In the example below I transform it into int, but not all actions don't work

Element Plus Playground

@adapt0
Copy link

adapt0 commented Apr 28, 2024

Couple of things to keep in mind:

  • el-table can sort the data for you (see sort-method), no need to mutate your data directly (don't use data.value.sort)
  • similarly el-table handles ascending/descending order, no need to mutate data for that either
  • sort comparison function argument order is not guaranteed. Consider compareFunction('333', 'Never Realized')

Here's an updated example which uses sort-method, will sort the mixture of strings & numbers, and doesn't mutate the data:
Element Plus Playground

@leeobrum
Copy link
Author

@adapt0 you helped me a lot, thank you!! xd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants