scroll to top on page change

This commit is contained in:
Daniel Ponte 2025-02-17 13:20:18 -05:00
parent a6a629f2fe
commit 3fa6ffdec1
2 changed files with 7 additions and 3 deletions

View file

@ -101,7 +101,7 @@
</form> </form>
</div> </div>
<div class="tabContainer" *ngIf="!isLoading; else spinner"> <div class="tabContainer" *ngIf="!isLoading; else spinner">
<table class="callsTable" mat-table [dataSource]="callsResult"> <table #callsTable class="callsTable" mat-table [dataSource]="callsResult">
<ng-container matColumnDef="select"> <ng-container matColumnDef="select">
<th mat-header-cell *matHeaderCellDef> <th mat-header-cell *matHeaderCellDef>
<mat-checkbox <mat-checkbox

View file

@ -1,7 +1,7 @@
import { Component, inject, ViewChild } from '@angular/core'; import { Component, ElementRef, inject, ViewChild } from '@angular/core';
import { CommonModule, AsyncPipe } from '@angular/common'; import { CommonModule, AsyncPipe } from '@angular/common';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { MatTableModule } from '@angular/material/table'; import { MatTable, MatTableModule } from '@angular/material/table';
import { import {
MatPaginator, MatPaginator,
MatPaginatorModule, MatPaginatorModule,
@ -80,6 +80,7 @@ const reqPageSize = 200;
export class CallsComponent { export class CallsComponent {
callsResult = new BehaviorSubject(new Array<CallRecord>(0)); callsResult = new BehaviorSubject(new Array<CallRecord>(0));
@ViewChild('paginator') paginator!: MatPaginator; @ViewChild('paginator') paginator!: MatPaginator;
@ViewChild('callsTable', { read: ElementRef }) callsTable!: ElementRef;
count = 0; count = 0;
dialog = inject(MatDialog); dialog = inject(MatDialog);
page = 0; page = 0;
@ -188,6 +189,9 @@ export class CallsComponent {
setPage(p: PageEvent, force?: boolean) { setPage(p: PageEvent, force?: boolean) {
this.selection.clear(); this.selection.clear();
this.curPage = p; this.curPage = p;
if (this.callsTable) {
this.callsTable.nativeElement.scrollIntoView(true);
}
if (p && p!.pageSize != this.perPage) { if (p && p!.pageSize != this.perPage) {
this.perPage = p!.pageSize; this.perPage = p!.pageSize;
this.prefsSvc.set('callsPerPage', p!.pageSize); this.prefsSvc.set('callsPerPage', p!.pageSize);