probe list table

This commit is contained in:
insanity 2018-01-31 12:56:09 +09:00
parent 75223ac370
commit f4d4ef76c3
2 changed files with 63 additions and 50 deletions

View File

@ -1,32 +1,43 @@
<div class="example-container mat-elevation-z8"> <div class="example-container mat-elevation-z8">
<mat-table #table [dataSource]="dataSource" matSort> <mat-table #table [dataSource]="dataSource" matSort>
<!-- Position Column -->
<ng-container matColumnDef="position">
<mat-header-cell *matHeaderCellDef mat-sort-header> No. </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.position}} </mat-cell>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name"> <ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef mat-sort-header> Name </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header> Name </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.name}} </mat-cell> <mat-cell *matCellDef="let element"> {{element.name}} </mat-cell>
</ng-container> </ng-container>
<!-- Weight Column --> <ng-container matColumnDef="ip">
<ng-container matColumnDef="weight"> <mat-header-cell *matHeaderCellDef mat-sort-header> IP </mat-header-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header> Weight </mat-header-cell> <mat-cell *matCellDef="let element"> {{element.ip}} </mat-cell>
<mat-cell *matCellDef="let element"> {{element.weight}} </mat-cell>
</ng-container> </ng-container>
<!-- Symbol Column --> <ng-container matColumnDef="os">
<ng-container matColumnDef="symbol"> <mat-header-cell *matHeaderCellDef mat-sort-header> OS </mat-header-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header> Symbol </mat-header-cell> <mat-cell *matCellDef="let element"> {{element.os}} </mat-cell>
<mat-cell *matCellDef="let element"> {{element.symbol}} </mat-cell> </ng-container>
<ng-container matColumnDef="cidr">
<mat-header-cell *matHeaderCellDef mat-sort-header> CIDR </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.cidr}} </mat-cell>
</ng-container>
<ng-container matColumnDef="targetCnt">
<mat-header-cell *matHeaderCellDef mat-sort-header> Targets </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.targetCnt}} </mat-cell>
</ng-container>
<ng-container matColumnDef="date">
<mat-header-cell *matHeaderCellDef mat-sort-header> Date </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.date}} </mat-cell>
</ng-container>
<ng-container matColumnDef="authBy">
<mat-header-cell *matHeaderCellDef mat-sort-header> AuthBy </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.authBy}} </mat-cell>
</ng-container> </ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns" ></mat-header-row> <mat-header-row *matHeaderRowDef="displayedColumns" ></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row> <mat-row *matRowDef="let row; columns: displayedColumns;" (click)="handleRowClick(row)"></mat-row>
</mat-table> </mat-table>
<mat-paginator [length]="length" [pageSize]="pageSize" [pageSizeOptions]="pageSizeOptions" (page)="pageEvent = $event"> <mat-paginator [length]="length" [pageSize]="pageSize" [pageSizeOptions]="pageSizeOptions" (page)="pageEvent = $event">

View File

@ -1,54 +1,52 @@
import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core'; import { Component, OnInit, AfterViewInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatSort } from '@angular/material'; import { MatTableDataSource, MatSort } from '@angular/material';
import { AfterContentInit } from '@angular/core/src/metadata/lifecycle_hooks';
export interface Element { export interface Probe {
id: string;
name: string; name: string;
position: number; ip: string;
weight: number; os: string;
symbol: string; cidr: string;
targetCnt: number;
date: string;
authBy: string;
} }
const ELEMENT_DATA: Element[] = [
{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.811, symbol: 'B'},
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
{position: 11, name: 'Sodium', weight: 22.9897, symbol: 'Na'},
{position: 12, name: 'Magnesium', weight: 24.305, symbol: 'Mg'},
{position: 13, name: 'Aluminum', weight: 26.9815, symbol: 'Al'},
{position: 14, name: 'Silicon', weight: 28.0855, symbol: 'Si'},
{position: 15, name: 'Phosphorus', weight: 30.9738, symbol: 'P'},
{position: 16, name: 'Sulfur', weight: 32.065, symbol: 'S'},
{position: 17, name: 'Chlorine', weight: 35.453, symbol: 'Cl'},
{position: 18, name: 'Argon', weight: 39.948, symbol: 'Ar'},
{position: 19, name: 'Potassium', weight: 39.0983, symbol: 'K'},
{position: 20, name: 'Calcium', weight: 40.078, symbol: 'Ca'},
];
@Component({ @Component({
selector: 'of-probe-list', selector: 'of-probe-list',
templateUrl: './list.component.html', templateUrl: './list.component.html',
styleUrls: ['./list.component.scss'] styleUrls: ['./list.component.scss']
}) })
export class ListComponent implements OnInit { export class ListComponent implements OnInit, AfterContentInit {
displayedColumns = ['position', 'name', 'weight', 'symbol']; displayedColumns = ['name', 'ip', 'os', 'cidr', 'targetCnt', 'date', 'authBy'];
dataSource = new MatTableDataSource(ELEMENT_DATA); dataSource: MatTableDataSource<Probe>;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
/** /**
* Set the sort after the view init since this component will * Set the sort after the view init since this component will
* be able to query its view for the initialized sort. * be able to query its view for the initialized sort.
*/ */
ngAfterViewInit() { ngAfterContentInit() {
console.log('after view init'); // temporary data
const data: Probe[] = new Array();
for (let i = 0; i < 10; i++) {
const p: Probe = {
id: String('id' + i),
name: String('name' + i),
ip: String('ip' + i),
os: String('os' + i),
cidr: String('cidr' + i),
targetCnt : i,
date: String('date' + i),
authBy: String('insanity')
};
data.push(p);
}
this.dataSource = new MatTableDataSource(data);
this.dataSource.sort = this.sort; this.dataSource.sort = this.sort;
} }
@ -56,4 +54,8 @@ export class ListComponent implements OnInit {
ngOnInit() { ngOnInit() {
} }
handleRowClick(obj: Probe) {
alert(obj.id);
}
} }