Angular mat table是一种用于构建数据展示表格的Angular Material组件。它提供了一种易于使用的方式来处理大量的数据,并具有可排序、过滤和分页功能。
下面是示例代码:
import { MatTableModule } from '@angular/material/table'; import { MatPaginatorModule } from '@angular/material/paginator'; import { MatSortModule } from '@angular/material/sort'; import { MatInputModule } from '@angular/material/input'; import { MatFormFieldModule } from '@angular/material/form-field'; import { CdkTableModule } from '@angular/cdk/table';
@NgModule({ imports: [ MatTableModule, MatPaginatorModule, MatSortModule, MatInputModule, MatFormFieldModule, CdkTableModule ] })
import { Component } from '@angular/core';
export interface PeriodicElement { name: string; position: number; weight: number; symbol: string; }
const ELEMENT_DATA: PeriodicElement[] = [ {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'}, {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'}, {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'}, {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'}, {position: 5, name: 'Boron', weight: 10.81, symbol: 'B'}, ];
@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] })
export class AppComponent { displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; dataSource = ELEMENT_DATA; }