Skip to content

Commit

Permalink
fix(ngrid): pagination reset when filter is on
Browse files Browse the repository at this point in the history
Fixes #78
  • Loading branch information
shlomiassaf committed Dec 22, 2020
1 parent f527875 commit 468de4f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<pbl-ngrid blockUi [dataSource]="ds" [columns]="columns" usePagination>
<pbl-ngrid blockUi [dataSource]="ds" [columns]="columns" usePagination matSort>
<my-grid-action-row filter label="My Grid"></my-grid-action-row>
<pbl-ngrid-paginator *pblNgridPaginatorRef="let table"
[table]="table"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { PblNgridModule } from '@pebula/ngrid';
import { PblNgridBlockUiModule } from '@pebula/ngrid/block-ui';
import { PblNgridPaginatorModule } from '@pebula/ngrid-material/paginator';
import { PblNgridMatSortModule } from '@pebula/ngrid-material/sort';

import { BindNgModule } from '@pebula/apps/docs-app-lib';
import { ExampleCommonModule } from '@pebula/apps/docs-app-lib/example-common.module';
Expand All @@ -20,7 +21,7 @@ import { ActionRowExample, MyGridActionRowComponent } from './action-row.compone
CommonModule,
MatIconModule, MatInputModule, MatButtonModule, MatFormFieldModule,
ExampleCommonModule,
PblNgridModule, PblNgridBlockUiModule, PblNgridPaginatorModule,
PblNgridModule, PblNgridBlockUiModule, PblNgridPaginatorModule, PblNgridMatSortModule,
],
exports: [ ActionRowExample ],
})
Expand Down
13 changes: 7 additions & 6 deletions libs/ngrid/core/src/lib/data-source/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,13 @@ export class PblDataSourceAdapter<T = any,

// we check if filter was asked, but also if we have a filter we re-run
// Only sorting is cached at this point filtering is always calculated
if (withChanges.filter || (!config.filter && event.filter.curr && event.filter.curr.filter)) {
if (withChanges.filter || (!config.filter && event.filter.curr?.filter)) {
data = this._lastFilteredSource = this.applyFilter(data, event.filter.curr || event.filter.prev);
if (!this.config.pagination) {
if (withChanges.filter || !withChanges.pagination) {
this.resetPagination(data.length);
}
}
}

if (withChanges.pagination) {
Expand Down Expand Up @@ -315,11 +320,7 @@ export class PblDataSourceAdapter<T = any,
}

protected applyFilter(data: T[], dataSourceFilter: DataSourceFilter): T[] {
data = filteringFn(data, dataSourceFilter);
if (!this.config.pagination) {
this.resetPagination(data.length);
}
return data;
return filteringFn(data, dataSourceFilter);
}

protected applySort(data: T[], event: PblNgridDataSourceSortChange): T[] {
Expand Down

0 comments on commit 468de4f

Please sign in to comment.