-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(table): data source should sort empty values correctly #8698
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(table): data source should sort empty values correctly #8698
Conversation
|
This line: |
2ae2bd4 to
d75aae8
Compare
|
Good call - forgot about the case of them being equal and remaining at 0. Thanks |
src/cdk/coercion/number-property.ts
Outdated
| } | ||
|
|
||
| /** Whether the provided value is considered a number. */ | ||
| export function isNumberValue(value: any): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this should be exposed as a public API under coercion. Mark this as internal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked as docs-private
src/cdk/coercion/number-property.ts
Outdated
| * Whether the provided value is considered a number. | ||
| * @docs-private | ||
| */ | ||
| export function isNumberValue(value: any): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to prefix with an _ to make it completely clear that this is not a public API (rather than being public and undocumented)
src/lib/table/table-data-source.ts
Outdated
| sortingDataAccessor: ((data: T, sortHeaderId: string) => string|number) = | ||
| (data: T, sortHeaderId: string): string|number => { | ||
| const value: any = data[sortHeaderId]; | ||
| let value: any = data[sortHeaderId]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
src/lib/table/table-data-source.ts
Outdated
| return value; | ||
| } | ||
| /** | ||
| * Returns a sorted array of the provided data according to the state of the MatSort. Called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Returns a sorted array..." -> "Gets a sorted copy of the data array based on the state of the MatSort"
src/lib/table/table-data-source.ts
Outdated
| * @param data The array of data that should be sorted. | ||
| * @param sort The connected MatSort that holds the current sort state. | ||
| */ | ||
| sortPredicate: ((data: T[], sort: MatSort) => T[]) = (data: T[], sort: MatSort): T[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A "predicate" is a function that returns true or false, so this isn't quite the right name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any suggestions? Just sort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh duh, sort is an input for the MatSort. Hmm, what about...sortData? Kinda fits with the function using sortDataAccessor
src/lib/table/table-data-source.ts
Outdated
| * @param data The array of data that should be sorted. | ||
| * @param sort The connected MatSort that holds the current sort state. | ||
| */ | ||
| sortPredicate: ((data: T[], sort: MatSort) => T[]) = (data: T[], sort: MatSort): T[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new API would really make this a minor release change
| comparatorResult = -1; | ||
| } | ||
| } else if (valueA) { | ||
| comparatorResult = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment that explains how you treat null/undefined for sorting (that they come first)
36390a9 to
4422bde
Compare
4422bde to
a3087cb
Compare
|
Ready for re-review |
jelbourn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Also takes the sort function and adds it as an override-able predicate for users to inject their own method of sorting. It takes a
MatSortrather than theactiveanddirectiveproperties in hopes that it's more stable in case we add properties toMatSortlater on. Open to opinions on whether that's wise or notFixes #8485