Skip to content

Commit

Permalink
DMP tables: Fix the pagination of the DMP table.
Browse files Browse the repository at this point in the history
  • Loading branch information
andresTabiTuwien committed Dec 9, 2024
1 parent 6465994 commit 364f086
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@ <h3 matTooltip="Edit DMP">
class="mat-elevation-z8"
[pageSize]="10"
[pageSizeOptions]="[10, 15, 20]"
[length]="length"
showFirstLastButtons="true"></mat-paginator>
</div>
12 changes: 8 additions & 4 deletions libs/damap/src/lib/widgets/dmp-table/dmp-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class DmpTableComponent implements OnChanges, AfterViewInit {
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;

length: number;
searchTerm: string = '';

readonly tableHeaders: string[] = [
Expand All @@ -51,7 +52,7 @@ export class DmpTableComponent implements OnChanges, AfterViewInit {

ngOnChanges(changes: SimpleChanges) {
if (changes.dmps) {
this.dataSource.data = this.dmps;
this.dataSource.data = this.dmps || [];
}
}

Expand All @@ -62,8 +63,6 @@ export class DmpTableComponent implements OnChanges, AfterViewInit {
data.latestVersionName?.toLowerCase().includes(filter) ||
data.versionCount?.toString().includes(filter) ||
data.id.toString().includes(filter);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
this.dataSource.sortingDataAccessor = (
item: DmpListItem,
property: string,
Expand All @@ -81,14 +80,19 @@ export class DmpTableComponent implements OnChanges, AfterViewInit {
return item[property];
}
};
this.dataSource.sort = this.sort;
setTimeout(() => {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}, 250);
}

applyFilter(filterValue: string) {
this.searchTerm = filterValue;
this.dataSource.filter = filterValue.trim().toLowerCase();

if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
this.length = this.dataSource.data.length;
}
}

Expand Down
1 change: 1 addition & 0 deletions libs/damap/src/lib/widgets/dmp-table/dmp-table.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { SharedModule } from '../../shared/shared.module';
MatSortModule,
MatMenuModule,
MatTooltipModule,
MatPaginatorModule,
],
declarations: [DmpTableComponent],
exports: [
Expand Down

0 comments on commit 364f086

Please sign in to comment.