-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pagination): Add pagination sample using mat-paginator
- Loading branch information
1 parent
f8afdc0
commit d583ebe
Showing
8 changed files
with
298 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
apps/demo/src/app/flight-search-with-pagination/flight-search-with-pagination.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<h2 class="title">Flight Search (Pagination)</h2> | ||
|
||
|
||
<form (ngSubmit)="search()"> | ||
<div> | ||
<mat-form-field> | ||
<mat-label>Name</mat-label> | ||
<input [(ngModel)]="searchParams.from" name="from" matInput /> | ||
</mat-form-field> | ||
</div> | ||
|
||
<div> | ||
<mat-form-field> | ||
<mat-label>Name</mat-label> | ||
<input [(ngModel)]="searchParams.to" name="to" matInput /> | ||
</mat-form-field> | ||
</div> | ||
|
||
<button mat-raised-button>Search</button> | ||
</form> | ||
|
||
<mat-table [dataSource]="dataSource"> | ||
<!-- From Column --> | ||
<ng-container matColumnDef="from"> | ||
<mat-header-cell *matHeaderCellDef>From</mat-header-cell> | ||
<mat-cell *matCellDef="let element">{{ element.from }}</mat-cell> | ||
</ng-container> | ||
|
||
<!-- To Column --> | ||
<ng-container matColumnDef="to"> | ||
<mat-header-cell *matHeaderCellDef>To</mat-header-cell> | ||
<mat-cell *matCellDef="let element">{{ element.to }}</mat-cell> | ||
</ng-container> | ||
|
||
<!-- Date Column --> | ||
<ng-container matColumnDef="date"> | ||
<mat-header-cell mat-header-cell *matHeaderCellDef>Date</mat-header-cell> | ||
<mat-cell mat-cell *matCellDef="let element">{{ | ||
element.date | date | ||
}}</mat-cell> | ||
</ng-container> | ||
|
||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> | ||
<mat-row | ||
*matRowDef="let row; columns: displayedColumns" | ||
(click)="selection.toggle(row)" | ||
></mat-row> | ||
</mat-table> | ||
<mat-paginator [length]="flightStore.flightTotalCount()" | ||
[pageSize]="flightStore.flightPageSize()" | ||
[pageIndex]="flightStore.flightCurrentPage()" | ||
[showFirstLastButtons]="true" | ||
[pageSizeOptions]="[5, 10, 25]" | ||
(page)="handlePageEvent($event)" | ||
aria-label="Select page"> | ||
</mat-paginator> |
52 changes: 52 additions & 0 deletions
52
apps/demo/src/app/flight-search-with-pagination/flight-search-with-pagination.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Component, effect, inject } from '@angular/core'; | ||
import { MatTableDataSource, MatTableModule } from '@angular/material/table'; | ||
import { DatePipe } from '@angular/common'; | ||
import { SelectionModel } from '@angular/cdk/collections'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { FlightBookingStore } from './flight-store'; | ||
import { Flight } from '../shared/flight'; | ||
import { MatPaginatorModule, PageEvent } from '@angular/material/paginator'; | ||
|
||
@Component({ | ||
selector: 'demo-flight-search-with-pagination', | ||
templateUrl: 'flight-search-with-pagination.component.html', | ||
standalone: true, | ||
imports: [ | ||
MatTableModule, | ||
MatPaginatorModule, | ||
DatePipe, | ||
MatInputModule, | ||
FormsModule, | ||
MatButtonModule, | ||
], | ||
providers: [FlightBookingStore] | ||
}) | ||
export class FlightSearchWithPaginationComponent { | ||
searchParams: { from: string; to: string } = { from: 'Wien', to: '' }; | ||
flightStore = inject(FlightBookingStore); | ||
|
||
displayedColumns: string[] = ['from', 'to', 'date']; | ||
dataSource = new MatTableDataSource<Flight>([]); | ||
selection = new SelectionModel<Flight>(true, []); | ||
|
||
constructor() { | ||
effect(() => { | ||
this.dataSource.data = this.flightStore.selectedPageFlightEntities(); | ||
}); | ||
this.flightStore.loadFlightEntities(); | ||
} | ||
|
||
search() { | ||
this.flightStore.updateFlightFilter( | ||
this.searchParams | ||
); | ||
this.flightStore.loadFlightEntities(); | ||
} | ||
|
||
handlePageEvent(e: PageEvent) { | ||
this.flightStore.setFlightPageSize(e.pageSize); | ||
this.flightStore.gotoFlightPage(e.pageIndex); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
apps/demo/src/app/flight-search-with-pagination/flight-store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FlightService } from '../shared/flight.service'; | ||
|
||
import { signalStore, type } from '@ngrx/signals'; | ||
|
||
import { withEntities } from '@ngrx/signals/entities'; | ||
import { withCallState, withDataService, withPagination } from 'ngrx-toolkit'; | ||
import { Flight } from '../shared/flight'; | ||
|
||
export const FlightBookingStore = signalStore( | ||
withCallState({ | ||
collection: 'flight', | ||
}), | ||
withEntities({ | ||
entity: type<Flight>(), | ||
collection: 'flight', | ||
}), | ||
withDataService({ | ||
dataServiceType: FlightService, | ||
filter: { from: 'Wien', to: '' }, | ||
collection: 'flight', | ||
}), | ||
withPagination({ | ||
entity: type<Flight>(), | ||
collection: 'flight', | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.