Skip to content

Commit

Permalink
Deprecate clearSummaryCache and recalculateSummaries methods (#3380)
Browse files Browse the repository at this point in the history
* fix(summaries): clear summary cache on data set #3379

* fix(summaries): deprecate clearSummaryCache and recalculateSummaries #3379

# Conflicts:
#	projects/igniteui-angular/src/lib/grids/grid-base.component.ts

* fix(summaries): call summaryService.clearSummaryCache #3379
  • Loading branch information
DiyanDimitrov authored and gedinakova committed Dec 12, 2018
1 parent eceaa09 commit 826be23
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
1 change: 0 additions & 1 deletion projects/igniteui-angular/src/lib/grids/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ Here is a list of all public methods exposed by **igx-grid**:
|`enableSummaries(expressions: Array)`|Enable summaries for the columns and apply your `customSummary` if it is provided.|
|`disableSummaries(fieldName: string)`|Disable summaries for the specified column.|
|`disableSummaries(columns: string[])`|Disable summaries for the listed columns.|
|`clearSummaryCache()`|Delete all cached summaries and force recalculation.|
|`previousPage()`|Goes to the previous page if paging is enabled and the current page is not the first.|
|`nextPage()`|Goes to the next page if paging is enabled and current page is not the last.|
|`paginate(page: number)`|Goes to the specified page if paging is enabled. Page indices are 0 based.|
Expand Down
4 changes: 2 additions & 2 deletions projects/igniteui-angular/src/lib/grids/column.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class IgxColumnComponent implements AfterContentInit {
this._hasSummary = value;

if (this.grid) {
this.grid.recalculateSummaries();
this.grid.summaryService.recalculateSummaries();
}
}
/**
Expand Down Expand Up @@ -468,7 +468,7 @@ export class IgxColumnComponent implements AfterContentInit {
if (this.grid) {
this.grid.summaryService.removeSummariesCachePerColumn(this.field);
(this.grid as any)._summaryPipeTrigger++;
this.grid.recalculateSummaries();
this.grid.summaryService.recalculateSummaries();
}
}
/**
Expand Down
29 changes: 18 additions & 11 deletions projects/igniteui-angular/src/lib/grids/grid-base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { IGridResourceStrings } from '../core/i18n/grid-resources';
import { CurrentResourceStrings } from '../core/i18n/resources';
import { IgxGridSummaryService } from './summaries/grid-summary.service';
import { IgxSummaryRowComponent } from './summaries/summary-row.component';
import { DeprecateMethod } from '../core/deprecateDecorators';

const MINIMUM_COLUMN_WIDTH = 136;
const FILTER_ROW_HEIGHT = 50;
Expand Down Expand Up @@ -164,6 +165,7 @@ export enum GridSummaryCalculationMode {
}

export abstract class IgxGridBaseComponent extends DisplayDensityBase implements OnInit, OnDestroy, AfterContentInit, AfterViewInit {
private _data: any[];

/**
* An @Input property that lets you fill the `IgxGridComponent` with an array of data.
Expand All @@ -173,7 +175,14 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
* @memberof IgxGridBaseComponent
*/
@Input()
public data: any[];
public get data(): any[] {
return this._data;
}

public set data(value: any[]) {
this._data = value;
this.summaryService.clearSummaryCache();
}

private _resourceStrings = CurrentResourceStrings.GridResStrings;
private _emptyGridMessage = null;
Expand Down Expand Up @@ -278,7 +287,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this._filteringExpressionsTree = filteringExpressionTreeClone;

this.filteringService.refreshExpressions();
this.clearSummaryCache();
this.summaryService.clearSummaryCache();
this.markForCheck();
}
}
Expand Down Expand Up @@ -2264,7 +2273,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this.calcRowCheckboxWidth = 0;

this.onRowAdded.pipe(takeUntil(this.destroy$)).subscribe((args) => this.refreshGridState(args));
this.onRowDeleted.pipe(takeUntil(this.destroy$)).subscribe((args) => this.clearSummaryCache(args));
this.onRowDeleted.pipe(takeUntil(this.destroy$)).subscribe((args) => this.summaryService.clearSummaryCache(args));
this.onFilteringDone.pipe(takeUntil(this.destroy$)).subscribe(() => this.endEdit(true));
this.onColumnMoving.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.endEdit(true);
Expand All @@ -2273,7 +2282,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this.onPagingDone.pipe(takeUntil(this.destroy$)).subscribe(() => this.endEdit(true));
this.onSortingDone.pipe(takeUntil(this.destroy$)).subscribe(() => this.endEdit(true));
this.transactions.onStateUpdate.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.clearSummaryCache();
this.summaryService.clearSummaryCache();
this._pipeTrigger++;
this.markForCheck();
});
Expand Down Expand Up @@ -2302,15 +2311,15 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
this.initColumns(this.columnList);

diff.forEachAddedItem((record: IterableChangeRecord<IgxColumnComponent>) => {
this.clearSummaryCache();
this.summaryService.clearSummaryCache();
this.calculateGridSizes();
this.onColumnInit.emit(record.item);
});

requestAnimationFrame(() => {
diff.forEachRemovedItem((record: IterableChangeRecord<IgxColumnComponent>) => {
// Recalculate Summaries
this.clearSummaryCache();
this.summaryService.clearSummaryCache();
this.calculateGridSizes();

// Clear Filtering
Expand Down Expand Up @@ -3296,16 +3305,16 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
/**
* @hidden
*/
@DeprecateMethod('There is no need to call clearSummaryCache method.The summary cache is cleared automatically when needed.')
public clearSummaryCache(args?) {
this.summaryService.clearSummaryCache(args);
}

/**
* @hidden
*/
public refreshGridState(args?) {
this.endEdit(true);
this.clearSummaryCache(args);
this.summaryService.clearSummaryCache(args);
}

// TODO: We have return values here. Move them to event args ??
Expand Down Expand Up @@ -3353,10 +3362,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
/**
* @hidden
*/
@DeprecateMethod('There is no need to call recalculateSummaries method. The summaries are recalculated automatically when needed.')
public recalculateSummaries() {
this.summaryService.resetSummaryHeight();
this.calculateGridHeight();
this.cdr.detectChanges();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ export class IgxGridSummaryService {
public groupingExpressions = [];
public retriggerRootPipe = false;

public recalculateSummaries() {
this.resetSummaryHeight();
this.grid.calculateGridHeight();
this.grid.cdr.detectChanges();
}

public clearSummaryCache(args?) {
if (!args) {
this.summaryCacheMap.clear();
if (this.grid.rootSummariesEnabled) {
if (this.grid && this.grid.rootSummariesEnabled) {
this.retriggerRootPipe = !this.retriggerRootPipe;
}
return;
Expand Down
1 change: 0 additions & 1 deletion src/app/grid-summaries/grid-summaries.sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ export class GridSummaryComponent implements OnInit {
updateData() {
const d = [].concat(this.data).concat(this.data.slice(0, 15));
this.data = d;
this.grid1.clearSummaryCache();
}

viewRecord(aRecord) { }
Expand Down

0 comments on commit 826be23

Please sign in to comment.