Strict done!!
This commit is contained in:
@ -12,7 +12,7 @@ function compare(a: string | number, b: string | number, isAsc: boolean) {
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
export class EmployeeListDataSource extends DataSource<Employee> {
|
||||
private filterValue: string = "";
|
||||
private filterValue = '';
|
||||
|
||||
constructor(
|
||||
public data: Employee[],
|
||||
@ -94,7 +94,7 @@ export class EmployeeListDataSource extends DataSource<Employee> {
|
||||
case 'joiningDate':
|
||||
return compare(a.joiningDate, b.joiningDate, isAsc);
|
||||
case 'leavingDate':
|
||||
return compare(a.leavingDate || "", b.leavingDate || "", isAsc);
|
||||
return compare(a.leavingDate || '', b.leavingDate || '', isAsc);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
@ -23,7 +23,7 @@ export class EmployeeListComponent implements OnInit, AfterViewInit {
|
||||
dataSource: EmployeeListDataSource;
|
||||
filter: Observable<string>;
|
||||
form: FormGroup;
|
||||
list: Employee[];
|
||||
list: Employee[] = [];
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = [
|
||||
@ -41,13 +41,12 @@ export class EmployeeListComponent implements OnInit, AfterViewInit {
|
||||
this.form = this.fb.group({
|
||||
filter: '',
|
||||
});
|
||||
this.filter = this.listenToFilterChange();
|
||||
}
|
||||
|
||||
listenToFilterChange() {
|
||||
return this.form
|
||||
.get('filter')
|
||||
.valueChanges.pipe(startWith(''), debounceTime(150), distinctUntilChanged());
|
||||
this.filter = (this.form.get('filter') as FormControl).valueChanges.pipe(
|
||||
startWith(''),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
);
|
||||
this.dataSource = new EmployeeListDataSource(this.list, this.filter);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@ -56,12 +55,12 @@ export class EmployeeListComponent implements OnInit, AfterViewInit {
|
||||
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new EmployeeListDataSource(this.paginator, this.sort, this.filter, this.list);
|
||||
this.dataSource = new EmployeeListDataSource(this.list, this.filter, this.paginator, this.sort);
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.filterElement.nativeElement.focus();
|
||||
if (this.filterElement) this.filterElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user