Skip to content

Commit

Permalink
fix(ngrid): do not auto-clear context on source changing
Browse files Browse the repository at this point in the history
BREAKING CHANGE
Until now, everytime the `onSourceChanging` event was fired, the context cache was automatically cleared.
This event is fired when `refresh()` is called and automatically clearing the context is bad, if the user wants to clear the cache he should do it by calling `grid.contextApi.clear()`.

The cache will still auto clear when the datasource is changed and when render data is changing without a primary key

To revert back to the old behavior you can set `clearContextOnSourceChanging` to true on the global configuration value for table.
  • Loading branch information
shlomiassaf committed Dec 3, 2020
1 parent 0c9ca4c commit e49d4ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libs/ngrid/src/lib/grid/ngrid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,12 @@ export class PblNgridComponent<T = any> implements AfterContentInit, AfterViewIn
// This is required because `onRenderDataChanging` is fired async, just before the data is emitted.
// Its not enough to clear the context when `setDataSource` is called, we also need to handle `refresh` calls which will not
// trigger this method.
value.onSourceChanging.pipe(unrx(this, value))
value.onSourceChanging
.pipe(unrx(this, value))
.subscribe( () => {
this._extApi.contextApi.clear();
if (this.config.get('table').clearContextOnSourceChanging) {
this._extApi.contextApi.clear();
}
});

// Run CD, scheduled as a micro-task, after each rendering
Expand Down
2 changes: 2 additions & 0 deletions libs/ngrid/src/lib/grid/services/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ export interface PblNgridConfig {
showHeader?: boolean;
showFooter?: boolean;
noFiller?: boolean;
clearContextOnSourceChanging?: boolean;
}
}

const DEFAULT_TABLE_CONFIG: PblNgridConfig['table'] = {
showHeader: true,
showFooter: false,
noFiller: false,
clearContextOnSourceChanging: false,
};

export const PEB_NGRID_CONFIG = new InjectionToken<PblNgridConfig>('PEB_NGRID_CONFIG');
Expand Down

0 comments on commit e49d4ff

Please sign in to comment.