@Component({
templateUrl: './tableresponsivedemo.html',
styles: [`
/* Column Priorities */
@media only all {
th.ui-p-6,
td.ui-p-6,
th.ui-p-5,
td.ui-p-5,
th.ui-p-4,
td.ui-p-4,
th.ui-p-3,
td.ui-p-3,
th.ui-p-2,
td.ui-p-2,
th.ui-p-1,
td.ui-p-1 {
display: none;
}
}
/* Show priority 1 at 320px (20em x 16px) */
@media screen and (min-width: 20em) {
th.ui-p-1,
td.ui-p-1 {
display: table-cell;
}
}
/* Show priority 2 at 480px (30em x 16px) */
@media screen and (min-width: 30em) {
th.ui-p-2,
td.ui-p-2 {
display: table-cell;
}
}
/* Show priority 3 at 640px (40em x 16px) */
@media screen and (min-width: 40em) {
th.ui-p-3,
td.ui-p-3 {
display: table-cell;
}
}
/* Show priority 4 at 800px (50em x 16px) */
@media screen and (min-width: 50em) {
th.ui-p-4,
td.ui-p-4 {
display: table-cell;
}
}
/* Show priority 5 at 960px (60em x 16px) */
@media screen and (min-width: 60em) {
th.ui-p-5,
td.ui-p-5 {
display: table-cell;
}
}
/* Show priority 6 at 1,120px (70em x 16px) */
@media screen and (min-width: 70em) {
th.ui-p-6,
td.ui-p-6 {
display: table-cell;
}
}
`]
})
export class TableResponsiveDemo implements OnInit {
cars: Car[];
cols: any[];
constructor(private carService: CarService) { }
ngOnInit() {
this.carService.getCarsSmall().then(cars => this.cars = cars);
this.cols = [
{ field: 'vin', header: 'Vin' },
{ field: 'year', header: 'Year' },
{ field: 'brand', header: 'Brand' },
{ field: 'color', header: 'Color' }
];
}
}
<h3 class="first">Reflow</h3>
<p-table [columns]="cols" [value]="cars" [responsive]="true">
<ng-template pTemplate="caption">
List of Cars
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
<span class="ui-column-title">{{col.header}}</span>
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
<ng-template pTemplate="summary">
There are {{cars?.length}} cars
</ng-template>
</p-table>
<h3>Priority</h3>
<p-table [columns]="cols" [value]="cars">
<ng-template pTemplate="caption">
List of Cars
</ng-template>
<ng-template pTemplate="header">
<tr>
<th>Vin</th>
<th class="ui-p-4">Year</th>
<th class="ui-p-5">Brand</th>
<th class="ui-p-6">Color</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td>{{car.vin}}</td>
<td class="ui-p-4">{{car.year}}</td>
<td class="ui-p-5">{{car.brand}}</td>
<td class="ui-p-6">{{car.color}}</td>
</tr>
</ng-template>
<ng-template pTemplate="summary">
There are {{cars?.length}} cars
</ng-template>
</p-table>