Skip to content

Commit a2129fc

Browse files
authored
fix(table): switch when arguments (#7516)
1 parent de8c6e2 commit a2129fc

File tree

5 files changed

+13
-14
lines changed

5 files changed

+13
-14
lines changed

src/cdk/table/row.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ export class CdkHeaderRowDef extends BaseRowDef {
8484
})
8585
export class CdkRowDef<T> extends BaseRowDef {
8686
/**
87-
* Function that should return true if this row template should be used for the provided row data
88-
* and index. If left undefined, this row will be considered the default row template to use when
89-
* no other when functions return true for the data.
87+
* Function that should return true if this row template should be used for the provided index
88+
* and row data. If left undefined, this row will be considered the default row template to use
89+
* when no other when functions return true for the data.
9090
* For every row, there must be at least one when function that passes or an undefined to default.
9191
*/
92-
when: (rowData: T, index: number) => boolean;
92+
when: (index: number, rowData: T) => boolean;
9393

9494
// TODO(andrewseguin): Add an input for providing a switch function to determine
9595
// if this template should be used.

src/cdk/table/table.spec.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,8 @@ class BooleanRowCdkTableApp {
750750
class WhenRowCdkTableApp {
751751
dataSource: FakeDataSource = new FakeDataSource();
752752
columnsToRender = ['column_a', 'column_b', 'column_c'];
753-
isIndex1 = (_rowData: TestData, index: number) => index == 1;
754-
hasC3 = (rowData: TestData) => rowData.c == 'c_3';
753+
isIndex1 = (index: number, _rowData: TestData) => index == 1;
754+
hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3';
755755

756756
constructor() { this.dataSource.addData(); }
757757

@@ -795,8 +795,8 @@ class WhenRowCdkTableApp {
795795
class WhenRowWithoutDefaultCdkTableApp {
796796
dataSource: FakeDataSource = new FakeDataSource();
797797
columnsToRender = ['column_a', 'column_b', 'column_c'];
798-
isIndex1 = (_rowData: TestData, index: number) => index == 1;
799-
hasC3 = (rowData: TestData) => rowData.c == 'c_3';
798+
isIndex1 = (index: number, _rowData: TestData) => index == 1;
799+
hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3';
800800

801801
@ViewChild(CdkTable) table: CdkTable<TestData>;
802802
}
@@ -839,8 +839,7 @@ class WhenRowWithoutDefaultCdkTableApp {
839839
class WhenRowMultipleDefaultsCdkTableApp {
840840
dataSource: FakeDataSource = new FakeDataSource();
841841
columnsToRender = ['column_a', 'column_b', 'column_c'];
842-
isIndex1 = (_rowData: TestData, index: number) => index == 1;
843-
hasC3 = (rowData: TestData) => rowData.c == 'c_3';
842+
hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3';
844843

845844
@ViewChild(CdkTable) table: CdkTable<TestData>;
846845
}

src/cdk/table/table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export class CdkTable<T> implements CollectionViewer {
340340
_getRowDef(data: T, i: number): CdkRowDef<T> {
341341
if (this._rowDefs.length == 1) { return this._rowDefs.first; }
342342

343-
let rowDef = this._rowDefs.find(def => def.when && def.when(data, i)) || this._defaultRowDef;
343+
let rowDef = this._rowDefs.find(def => def.when && def.when(i, data)) || this._defaultRowDef;
344344
if (!rowDef) { throw getTableMissingMatchingRowDefError(); }
345345

346346
return rowDef;

src/demo-app/table/table-demo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class TableDemo {
4545
@ViewChild(MatPaginator) paginator: MatPaginator;
4646
@ViewChild(MatSort) sort: MatSort;
4747

48-
isDetailRow = (row: DetailRow|UserData) => row.hasOwnProperty('detailRow');
48+
isDetailRow = (_index: number, row: DetailRow|UserData) => row.hasOwnProperty('detailRow');
4949

5050
@ViewChild('paginatorForDataSource') paginatorForDataSource: MatPaginator;
5151
@ViewChild('sortForDataSource') sortForDataSource: MatSort;

src/lib/table/table.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class FakeDataSource extends DataSource<TestData> {
285285
class MatTableApp {
286286
dataSource: FakeDataSource | null = new FakeDataSource();
287287
columnsToRender = ['column_a', 'column_b', 'column_c'];
288-
isFourthRow = (_rowData: TestData, i: number) => i == 3;
288+
isFourthRow = (i: number, _rowData: TestData) => i == 3;
289289

290290
@ViewChild(MatTable) table: MatTable<TestData>;
291291
}
@@ -311,7 +311,7 @@ class MatTableApp {
311311
})
312312
class MatTableWithWhenRowApp {
313313
dataSource: FakeDataSource | null = new FakeDataSource();
314-
isFourthRow = (_rowData: TestData, i: number) => i == 3;
314+
isFourthRow = (i: number, _rowData: TestData) => i == 3;
315315

316316
@ViewChild(MatTable) table: MatTable<TestData>;
317317
}

0 commit comments

Comments
 (0)