refactor: angular material components export from common module & feat: css helper classes added (#57)
* angular material export in common module * css helper class added
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import {MatPaginator, MatSort, MatTableDataSource} from '@angular/material';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-clients',
|
||||
@@ -7,9 +8,62 @@ import { Component, OnInit } from '@angular/core';
|
||||
})
|
||||
export class ClientsComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
displayedColumns = ['id', 'name', 'progress', 'color'];
|
||||
dataSource: MatTableDataSource<UserData>;
|
||||
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
|
||||
constructor() {
|
||||
// Create 100 users
|
||||
const users: UserData[] = [];
|
||||
for (let i = 1; i <= 100; i++) { users.push(createNewUser(i)); }
|
||||
|
||||
// Assign the data to the data source for the table to render
|
||||
this.dataSource = new MatTableDataSource(users);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sort = this.sort;
|
||||
}
|
||||
|
||||
applyFilter(filterValue: string) {
|
||||
filterValue = filterValue.trim(); // Remove whitespace
|
||||
filterValue = filterValue.toLowerCase(); // Datasource defaults to lowercase matches
|
||||
this.dataSource.filter = filterValue;
|
||||
if (this.dataSource.paginator) {
|
||||
this.dataSource.paginator.firstPage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/** Constants used to fill up our data base. */
|
||||
const COLORS = ['maroon', 'red', 'orange', 'yellow', 'olive', 'green', 'purple',
|
||||
'fuchsia', 'lime', 'teal', 'aqua', 'blue', 'navy', 'black', 'gray'];
|
||||
const NAMES = ['Maia', 'Asher', 'Olivia', 'Atticus', 'Amelia', 'Jack',
|
||||
'Charlotte', 'Theodore', 'Isla', 'Oliver', 'Isabella', 'Jasper',
|
||||
'Cora', 'Levi', 'Violet', 'Arthur', 'Mia', 'Thomas', 'Elizabeth'];
|
||||
/** Builds and returns a new User. */
|
||||
function createNewUser(id: number): UserData {
|
||||
const name =
|
||||
NAMES[Math.round(Math.random() * (NAMES.length - 1))] + ' ' +
|
||||
NAMES[Math.round(Math.random() * (NAMES.length - 1))].charAt(0) + '.';
|
||||
|
||||
return {
|
||||
id: id.toString(),
|
||||
name: name,
|
||||
progress: Math.round(Math.random() * 100).toString(),
|
||||
color: COLORS[Math.round(Math.random() * (COLORS.length - 1))]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
export interface UserData {
|
||||
id: string;
|
||||
name: string;
|
||||
progress: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user