File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313 class ="form-control "
1414 placeholder ="Search an item in the catalogue "
1515 [(ngModel)] ="search "
16- (ngModelChange) ="refresh( ) "
16+ (ngModelChange) ="onSearchChange($event ) "
1717 aria-label ="Search "
1818 aria-describedby ="search "
1919 />
4646
4747 < mat-paginator
4848 [pageIndex] ="page "
49- [length] ="items.length "
49+ [length] ="filteredLength( items) "
5050 [pageSize] ="catalogueService.CONF.pageSize "
5151 (page) ="onPageChange($event) "
5252 [hidePageSize] ="true "
Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ export class HomeComponent {
2323 this . cdRef . detectChanges ( ) ;
2424 }
2525
26+ onSearchChange ( value : string ) : void {
27+ // Ensure we reset to the first page when the search term changes
28+ this . page = 0 ;
29+ this . refresh ( ) ;
30+ }
31+
2632 onPageChange ( page : PageEvent ) : void {
2733 this . page = page . pageIndex ;
2834 }
@@ -44,4 +50,11 @@ export class HomeComponent {
4450 }
4551 return filteredItems . slice ( this . catalogueService . CONF . pageSize * this . page , this . catalogueService . CONF . pageSize * ( this . page + 1 ) ) ;
4652 }
53+
54+ filteredLength ( modules : Repository [ ] ) : number {
55+ if ( ! this . search ) {
56+ return modules . length ;
57+ }
58+ return modules . filter ( ( item ) => item . name . toLowerCase ( ) . indexOf ( this . search . toLowerCase ( ) ) > - 1 ) . length ;
59+ }
4760}
You can’t perform that action at this time.
0 commit comments