Skip to content

Commit e4102ea

Browse files
authored
fix(material/table): sort correctly
Sort correctly when column information contains string and number values Fixes angular#20140
1 parent 37f4a7a commit e4102ea

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/material/table/table-data-source.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ export class MatTableDataSource<T> extends DataSource<T> {
148148
let valueA = this.sortingDataAccessor(a, active);
149149
let valueB = this.sortingDataAccessor(b, active);
150150

151+
const valueAType = typeof valueA;
152+
const valueBType = typeof valueB;
153+
const sameType = valueAType === valueBType;
154+
if (!sameType) {
155+
valueA = valueAType === 'number' ? valueA.toString() : valueA;
156+
valueB = valueBType === 'number' ? valueB.toString() : valueB;
157+
}
158+
151159
// If both valueA and valueB exist (truthy), then compare the two. Otherwise, check if
152160
// one value exists while the other doesn't. In this case, existing value should come last.
153161
// This avoids inconsistent results when comparing values to undefined/null.

0 commit comments

Comments
 (0)