Skip to content

Commit

Permalink
fix(table): switch when arguments (#7516)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewseguin authored Oct 31, 2017
1 parent de8c6e2 commit a2129fc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/cdk/table/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ export class CdkHeaderRowDef extends BaseRowDef {
})
export class CdkRowDef<T> 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.
Expand Down
11 changes: 5 additions & 6 deletions src/cdk/table/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Expand Down Expand Up @@ -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<TestData>;
}
Expand Down Expand Up @@ -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<TestData>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export class CdkTable<T> implements CollectionViewer {
_getRowDef(data: T, i: number): CdkRowDef<T> {
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;
Expand Down
2 changes: 1 addition & 1 deletion src/demo-app/table/table-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/table/table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class FakeDataSource extends DataSource<TestData> {
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<TestData>;
}
Expand All @@ -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<TestData>;
}
Expand Down

0 comments on commit a2129fc

Please sign in to comment.