I am using angular 10, cdktable and I face the following problem.
when I execute a search on a table, my pagination do not update unless I click anywhere in the app (that it magically update)...
This is a change detection problem, my app is using onPush strategy.
now, my table is getting data from this observable
connect(): Observable < Advertisers_advertisers_rows[] > {
return this.store.pipe(
select(advertiserPage),
map((res) => {
this.itemTotal = res.data.records
this.page = res.data.page
return res?.data?.rows || []
})
)
}
note that here I am updating the total number of item and the page.
now, this is passed to the table component
table.component.ts
<app-table
[dataSource]="this"
[pagination]="paginationOptions"
(pageChange)="loadPage($event)"
[itemTotal]="itemTotal"
></app-table>
which call itself the pagination
pagination.ts:
<app-table-pagination
*ngIf="pagination"
[options]="pagination"
[(page)]="page"
(pageChange)="pageChange.emit($event)"
[total]="itemTotal"
></app-table-pagination>
If I follow the logic, the itemTotal
change, it is passed as input to table
and to pagination
so it should trigger a change.
Everything works if I do
connect(): Observable < Advertisers_advertisers_rows[] > {
return this.store.pipe(
select(advertiserPage),
map((res) => {
this.itemTotal = res.data.records
this.page = res.data.page
this.changeDetection.markForCheck()
return res?.data?.rows || []
})
)
}
But I do not understand why is this necessary.