components icon indicating copy to clipboard operation
components copied to clipboard

[Table] Negative numbers not sorted correctly

Open rscottfree opened this issue 8 years ago • 4 comments

Bug, feature request, or proposal:

A number field, if it's negative, gets sorted after 0 when sorting ascending.

What is the expected behavior?

Negative numbers come before 0 when sorting ascending.

What is the current behavior?

When sorting ascending, negative numbers come after 0 and before positive numbers.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-yfw5ia-uaqsrh?file=app%2Ftable-sorting-example.ts Click on the weight column header one time to sort ascending.

What is the use-case or motivation for changing an existing behavior?

It makes sense that -1 < 0 < 1 and I think the default sort comparison should follow that rule.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Material 5.2.2

Anything else

This is using the default sort with MatSort on a MatTable using MatTableDataSource.

rscottfree avatar Feb 26 '18 20:02 rscottfree

I also have this problem. Any fixes?

aleksanderhan avatar Mar 02 '18 13:03 aleksanderhan

@aleksanderhan A workaround is to use MatTableDataSource.sortData to override the sort mechanism.

rscottfree avatar Mar 02 '18 15:03 rscottfree

Should be fixed in https://github.com/angular/material2/pull/10561

andrewseguin avatar Apr 23 '18 20:04 andrewseguin

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.