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

Sorting on columns that aren't text doesn't seem to work correctly #880

Closed
scallin opened this issue Apr 20, 2021 · 6 comments
Closed

Sorting on columns that aren't text doesn't seem to work correctly #880

scallin opened this issue Apr 20, 2021 · 6 comments
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:enhancement New feature or enhancement of existing capability
Milestone

Comments

@scallin
Copy link

scallin commented Apr 20, 2021

Category

[ ] Enhancement

[ ] Bug

[X] Question

Version

Please specify what version of the library you are using: [ 1.19.0 ]

Expected / Desired Behavior / Question

Is there a way to override the default sorting functionality? Sorting is built in, but treats all content as text, so number columns (like item ID) and date columns do not sort correctly.

Observed Behavior

If I add ListView with list items and a column to show the ID of the list items like this:

const viewFields: IViewField[] = [
{
name: 'ID',
minWidth: 80,
maxWidth: 90,
isResizable: true,
displayName: 'ID',
sorting: true,
}
]

Clicking on the column will sort the items like this:
1
10
100
14
15
2
20
etc.

Steps to Reproduce

Steps are provided above.

Thanks!

@ghost
Copy link

ghost commented Apr 20, 2021

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

@ghost ghost added the Needs: Triage 🔍 label Apr 20, 2021
@HeShallNot
Copy link

Can confirm this issue as well. Sorting with column values that are numeric seems to be treated as strings instead which then fails to produce the correct order.

Here are some screenshots for both ascending and descending sorts of numeric columns failing to produce the correct order. An override function for sorting in the IViewField definition is a very good compromise as well.

image

image

@AJIXuMuK
Copy link
Collaborator

AJIXuMuK commented May 1, 2021

Thank you @scallin for reporting this one.
Not sure about v1 but in v2 and v3 sorting behavior depends on the type of actual data provided to the controls.
If Id has number value (like Id: 5) it will be sorted as number. If Id has string value (Id: '5') it will be sorted as string.

Here are examples
NUMBER
Screen Shot 2021-05-01 at 12 47 35 PM
Screen Shot 2021-05-01 at 12 48 08 PM

STRING
Screen Shot 2021-05-01 at 12 56 58 PM
Screen Shot 2021-05-01 at 12 58 35 PM

But, anyway, I've added a new prop sortItems that allows to override default sorting behavior.

sortItems?: (items: any[], columnName: string, descending: boolean) => any[];

It will be included in the next v2 and v3 releases.

@AJIXuMuK AJIXuMuK added this to the 3.1.0 milestone May 1, 2021
@HeShallNot
Copy link

@AJIXuMuK many thanks for the quick response on this issue. but any chance this could be applied to v1 as well? we have still have some tenants that needed to support v1. we have a local workaround but having an official fix would be really helpful in terms of maintainability.

Cheers~

@AJIXuMuK
Copy link
Collaborator

AJIXuMuK commented May 3, 2021

@HeShallNot - did you check that you provide numbers as field values, not strings?
I believe it should be enough in your situation.

We can add this to v1, but we release version really seldom for v1.

@kodofix
Copy link

kodofix commented Sep 19, 2022

@AJIXuMuK if it's possible It will be great if you will add this fix to v1 I'm working with on prem and I just come across this problem now that my listView control sorting alphabetic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:fixed-next-drop Issue will be fixed in upcoming release. type:enhancement New feature or enhancement of existing capability
Projects
None yet
Development

No branches or pull requests

4 participants