Hey*_*bat 4 angular-material angular
你如何从 HTML 中设置dataAccessorin mat-text-column?该文档不包含任何示例。请注意,的签名dataAccessor是一个函数:
dataAccessor: (data: T, name: string) => string;
Run Code Online (Sandbox Code Playgroud)
“ _renderPrice ”用作以下示例中的 dataAccessor 函数。该函数接收一个由 dataSource 定义的类型的对象作为参数,并且必须返回一个字符串。它为表中的每一行调用一次。
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'app-orderpositions',
template: `
<table mat-table [dataSource]="positions">
<mat-text-column name="price" justify="end"
[headerText]="'BESTELLUNG.POSITIONEN.PREIS' | translate"
[dataAccessor]="_renderPrice">
</mat-text-column>
<tr mat-header-row *matHeaderRowDef="_displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: _displayedColumns;"></tr>
</table>
`
})
export class OrderpositionsComponent {
@Input()
positions: Orderposition[];
readonly _displayedColumns: string[] = ['price'];
_renderPrice(position: Orderposition): string {
return `${position.price} EUR`;
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
1655 次 |
| 最近记录: |