Material Angular Table with All Features Part1
We will experiment with material angular tables' all feature.
Code Action @ StackBlitz
Before starting the experiment points to be done as below
- Pagination
- Sorting
- Filtering
- Selection
- Footer row
- Sticky Rows and Columns
DataSource
The simplest way to provide data to the table is by passing a data array to the table's data source input.MatTableDataSource is the best data source type for mat table. have to assign the array object to MatTableDataSource as below.
//in Html template
<
table mat-table [dataSource]="custSource" matSort class="mat-elevation-z8"
</ table >
// To Import
import {MatTableDataSource} from '@angular/material';
// in component declare MatTableDataSourcepublic custSource: any = new MatTableDataSource
Pagination
Api to import MatPaginatorModule as below in app.module.ts
import {MatPaginatorModule} from '@angular/material/paginator'
Add below code in html file at bottom of the Mat-table
<mat-paginator [pageSizeOptions]="[5, 10, 25, 100]"></mat-paginator>
in component.ts
import {MatTableDataSource, MatSort, MatPaginator} from '@angular/material';
// create a viewchild for matpaginator
@ViewChild(MatPaginator) paginator: MatPaginator;// Assign the paginator to datasource object
ngOnInit() {
this.custSource.paginator = this.paginator;
}
0 Comments