Skip to content

Commit 23cd1e3

Browse files
committed
Revert "fix(table): MatTableDataSource incorrectly sorting zero (angular#10561)"
This reverts commit bcb5697. The commit broke unit tests on master
1 parent edb57f9 commit 23cd1e3

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,16 @@ export class MatTableDataSource<T> extends DataSource<T> {
123123
// This avoids inconsistent results when comparing values to undefined/null.
124124
// If neither value exists, return 0 (equal).
125125
let comparatorResult = 0;
126-
if (valueA != null && valueB != null) {
126+
if (valueA && valueB) {
127127
// Check if one value is greater than the other; if equal, comparatorResult should remain 0.
128128
if (valueA > valueB) {
129129
comparatorResult = 1;
130130
} else if (valueA < valueB) {
131131
comparatorResult = -1;
132132
}
133-
} else if (valueA != null) {
133+
} else if (valueA) {
134134
comparatorResult = 1;
135-
} else if (valueB != null) {
135+
} else if (valueB) {
136136
comparatorResult = -1;
137137
}
138138

src/lib/table/table.spec.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -267,35 +267,6 @@ describe('MatTable', () => {
267267
]);
268268
});
269269

270-
it('should sort zero correctly', () => {
271-
// Activate column A sort
272-
dataSource.data[0].a = 1;
273-
dataSource.data[1].a = 0;
274-
dataSource.data[2].a = -1;
275-
276-
// Expect that zero comes after the negative numbers and before the positive ones.
277-
component.sort.sort(component.sortHeader);
278-
fixture.detectChanges();
279-
expectTableToMatchContent(tableElement, [
280-
['Column A\xa0Sorted by a ascending', 'Column B', 'Column C'],
281-
['-1', 'b_3', 'c_3'],
282-
['0', 'b_2', 'c_2'],
283-
['1', 'b_1', 'c_1'],
284-
]);
285-
286-
287-
// Expect that zero comes after the negative numbers and before
288-
// the positive ones when switching the sorting direction.
289-
component.sort.sort(component.sortHeader);
290-
fixture.detectChanges();
291-
expectTableToMatchContent(tableElement, [
292-
['Column A\xa0Sorted by a descending', 'Column B', 'Column C'],
293-
['1', 'b_1', 'c_1'],
294-
['0', 'b_2', 'c_2'],
295-
['-1', 'b_3', 'c_3'],
296-
]);
297-
});
298-
299270
it('should be able to page the table contents', fakeAsync(() => {
300271
// Add 100 rows, should only display first 5 since page length is 5
301272
for (let i = 0; i < 100; i++) {
@@ -328,9 +299,9 @@ describe('MatTable', () => {
328299
});
329300

330301
interface TestData {
331-
a: string|number|undefined;
332-
b: string|number|undefined;
333-
c: string|number|undefined;
302+
a: string|undefined;
303+
b: string|undefined;
304+
c: string|undefined;
334305
}
335306

336307
class FakeDataSource extends DataSource<TestData> {

0 commit comments

Comments
 (0)