mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(table): switch when arguments (#7516)
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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<TestData>;
|
||||
}
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user