From a2129fc7e7e2f20c93b387f5045d3a285e4e6ee0 Mon Sep 17 00:00:00 2001 From: Andrew Seguin Date: Tue, 31 Oct 2017 16:05:55 -0700 Subject: [PATCH] fix(table): switch when arguments (#7516) --- src/cdk/table/row.ts | 8 ++++---- src/cdk/table/table.spec.ts | 11 +++++------ src/cdk/table/table.ts | 2 +- src/demo-app/table/table-demo.ts | 2 +- src/lib/table/table.spec.ts | 4 ++-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/cdk/table/row.ts b/src/cdk/table/row.ts index 3a148a775951..615354624bb5 100644 --- a/src/cdk/table/row.ts +++ b/src/cdk/table/row.ts @@ -84,12 +84,12 @@ export class CdkHeaderRowDef extends BaseRowDef { }) export class CdkRowDef extends BaseRowDef { /** - * Function that should return true if this row template should be used for the provided row data - * and index. If left undefined, this row will be considered the default row template to use when - * no other when functions return true for the data. + * Function that should return true if this row template should be used for the provided index + * and row data. If left undefined, this row will be considered the default row template to use + * when no other when functions return true for the data. * For every row, there must be at least one when function that passes or an undefined to default. */ - when: (rowData: T, index: number) => boolean; + when: (index: number, rowData: T) => boolean; // TODO(andrewseguin): Add an input for providing a switch function to determine // if this template should be used. diff --git a/src/cdk/table/table.spec.ts b/src/cdk/table/table.spec.ts index ec9f85ae40fb..b659fefaac15 100644 --- a/src/cdk/table/table.spec.ts +++ b/src/cdk/table/table.spec.ts @@ -750,8 +750,8 @@ class BooleanRowCdkTableApp { class WhenRowCdkTableApp { dataSource: FakeDataSource = new FakeDataSource(); columnsToRender = ['column_a', 'column_b', 'column_c']; - isIndex1 = (_rowData: TestData, index: number) => index == 1; - hasC3 = (rowData: TestData) => rowData.c == 'c_3'; + isIndex1 = (index: number, _rowData: TestData) => index == 1; + hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3'; constructor() { this.dataSource.addData(); } @@ -795,8 +795,8 @@ class WhenRowCdkTableApp { class WhenRowWithoutDefaultCdkTableApp { dataSource: FakeDataSource = new FakeDataSource(); columnsToRender = ['column_a', 'column_b', 'column_c']; - isIndex1 = (_rowData: TestData, index: number) => index == 1; - hasC3 = (rowData: TestData) => rowData.c == 'c_3'; + isIndex1 = (index: number, _rowData: TestData) => index == 1; + hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3'; @ViewChild(CdkTable) table: CdkTable; } @@ -839,8 +839,7 @@ class WhenRowWithoutDefaultCdkTableApp { class WhenRowMultipleDefaultsCdkTableApp { dataSource: FakeDataSource = new FakeDataSource(); columnsToRender = ['column_a', 'column_b', 'column_c']; - isIndex1 = (_rowData: TestData, index: number) => index == 1; - hasC3 = (rowData: TestData) => rowData.c == 'c_3'; + hasC3 = (_index: number, rowData: TestData) => rowData.c == 'c_3'; @ViewChild(CdkTable) table: CdkTable; } diff --git a/src/cdk/table/table.ts b/src/cdk/table/table.ts index 6f0301decf5e..a21a3c2552a0 100644 --- a/src/cdk/table/table.ts +++ b/src/cdk/table/table.ts @@ -340,7 +340,7 @@ export class CdkTable implements CollectionViewer { _getRowDef(data: T, i: number): CdkRowDef { if (this._rowDefs.length == 1) { return this._rowDefs.first; } - let rowDef = this._rowDefs.find(def => def.when && def.when(data, i)) || this._defaultRowDef; + let rowDef = this._rowDefs.find(def => def.when && def.when(i, data)) || this._defaultRowDef; if (!rowDef) { throw getTableMissingMatchingRowDefError(); } return rowDef; diff --git a/src/demo-app/table/table-demo.ts b/src/demo-app/table/table-demo.ts index 691190cb73dc..c10015145426 100644 --- a/src/demo-app/table/table-demo.ts +++ b/src/demo-app/table/table-demo.ts @@ -45,7 +45,7 @@ export class TableDemo { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; - isDetailRow = (row: DetailRow|UserData) => row.hasOwnProperty('detailRow'); + isDetailRow = (_index: number, row: DetailRow|UserData) => row.hasOwnProperty('detailRow'); @ViewChild('paginatorForDataSource') paginatorForDataSource: MatPaginator; @ViewChild('sortForDataSource') sortForDataSource: MatSort; diff --git a/src/lib/table/table.spec.ts b/src/lib/table/table.spec.ts index eac0a880fff9..4296127c80b2 100644 --- a/src/lib/table/table.spec.ts +++ b/src/lib/table/table.spec.ts @@ -285,7 +285,7 @@ class FakeDataSource extends DataSource { class MatTableApp { dataSource: FakeDataSource | null = new FakeDataSource(); columnsToRender = ['column_a', 'column_b', 'column_c']; - isFourthRow = (_rowData: TestData, i: number) => i == 3; + isFourthRow = (i: number, _rowData: TestData) => i == 3; @ViewChild(MatTable) table: MatTable; } @@ -311,7 +311,7 @@ class MatTableApp { }) class MatTableWithWhenRowApp { dataSource: FakeDataSource | null = new FakeDataSource(); - isFourthRow = (_rowData: TestData, i: number) => i == 3; + isFourthRow = (i: number, _rowData: TestData) => i == 3; @ViewChild(MatTable) table: MatTable; }