primeng icon indicating copy to clipboard operation
primeng copied to clipboard

datatable is not allowing you to use different ChangeDetectionStrategies in enclosing components which use datatable

Open joe380 opened this issue 10 years ago • 1 comments

It is fairly easy to reproduce with the current beta.6 release:

  1. use https://github.com/primefaces/primeng-quickstart-webpack
  2. in app.component.ts add changeDetection: ChangeDetectionStrategy.OnPush
  3. only paginator with 1 page is shown but no data!

a quick fix (but this should be evaluated also for other components) is to add ChangeDetectorRef to constructor od datatable component like this:

constructor(private el: ElementRef, private domHandler: DomHandler, differs: IterableDiffers, 
        @Query(Column) cols: QueryList<Column>, private renderer: Renderer, changeDetector: ChangeDetectorRef) {
        this.differ = differs.find([]).create(null);
        cols.changes.subscribe(_ => {
            this.columns = cols.toArray();
            this.columnsUpdated = true;
            changeDetector.markForCheck();
        });
    }

Without this fix the usage of this component does not give you any space for optimization of your enclosing components, because you always have to use CheckAlways which is default change detection strategy.

joe380 avatar May 24 '16 15:05 joe380

Even If I set ChangeDetectionStrategy.OnPush the component keeps calling check when I click sorting

pantonis avatar Sep 04 '17 09:09 pantonis