From 8f5e00ba69d47bcb6f57a789705d66229736ce9b Mon Sep 17 00:00:00 2001 From: ttonev Date: Tue, 7 Jan 2025 17:55:05 +0200 Subject: [PATCH 1/4] fix(pivot-grid): added createRow method for grid based events --- .../grids/pivot-grid/pivot-grid.component.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts index 46a2253b17f..e255b44d3ca 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts @@ -102,6 +102,7 @@ import { IgxTextHighlightService } from '../../directives/text-highlight/text-hi import { IgxPivotRowHeaderGroupComponent } from './pivot-row-header-group.component'; import { IgxPivotDateDimension } from './pivot-grid-dimensions'; import { IgxPivotRowDimensionMrlRowComponent } from './pivot-row-dimension-mrl-row.component'; +import { IgxGridRow } from 'igniteui-angular'; let NEXT_ID = 0; const MINIMUM_COLUMN_WIDTH = 200; @@ -2510,4 +2511,20 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni this.regroupTrigger++; } } + + /** + * @hidden @internal + */ + public createRow(index: number, data?: any): RowType { + let row: RowType; + + const dataIndex = this._getDataViewIndex(index); + const rec = data ?? this.dataView[dataIndex]; + + + if (!row && rec) { + row = new IgxGridRow(this, index, rec); + } + return row; + } } From e0f02a8fe7e29f1385ee18c6b0ac74dfe6748746 Mon Sep 17 00:00:00 2001 From: ttonev Date: Thu, 9 Jan 2025 12:08:41 +0200 Subject: [PATCH 2/4] fix(pivot-grid): update import paths and add cell click event test --- .../grids/pivot-grid/pivot-grid.component.ts | 2 +- .../lib/grids/pivot-grid/pivot-grid.spec.ts | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts index e255b44d3ca..b5e3bb49694 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts @@ -102,7 +102,7 @@ import { IgxTextHighlightService } from '../../directives/text-highlight/text-hi import { IgxPivotRowHeaderGroupComponent } from './pivot-row-header-group.component'; import { IgxPivotDateDimension } from './pivot-grid-dimensions'; import { IgxPivotRowDimensionMrlRowComponent } from './pivot-row-dimension-mrl-row.component'; -import { IgxGridRow } from 'igniteui-angular'; +import { IgxGridRow } from '../grid-public-row'; let NEXT_ID = 0; const MINIMUM_COLUMN_WIDTH = 200; diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.spec.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.spec.ts index cc919d121ba..c474beba5b8 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.spec.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.spec.ts @@ -1,7 +1,7 @@ import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { FilteringExpressionsTree, FilteringLogic, GridColumnDataType, IgxIconComponent, IgxPivotGridComponent, IgxStringFilteringOperand } from 'igniteui-angular'; +import { CellType, FilteringExpressionsTree, FilteringLogic, GridColumnDataType, IGridCellEventArgs, IgxIconComponent, IgxPivotGridComponent, IgxStringFilteringOperand } from 'igniteui-angular'; import { IgxChipComponent } from '../../chips/chip.component'; import { IgxChipsAreaComponent } from '../../chips/chips-area.component'; import { DefaultPivotSortingStrategy } from '../../data-operations/pivot-sort-strategy'; @@ -23,6 +23,7 @@ import { Size } from '../common/enums'; import { setElementSize } from '../../test-utils/helper-utils.spec'; import { IgxPivotRowDimensionMrlRowComponent } from './pivot-row-dimension-mrl-row.component'; import { IgxPivotRowDimensionContentComponent } from './pivot-row-dimension-content.component'; +import { IgxGridCellComponent } from '../cell.component'; const CSS_CLASS_LIST = 'igx-drop-down__list'; const CSS_CLASS_ITEM = 'igx-drop-down__item'; @@ -2105,8 +2106,23 @@ describe('IgxPivotGrid #pivotGrid', () => { expect(pivotGrid.rowList.length).toBe(10); }); - }); + it('should have the correct IGridCellEventArgs when clicking on a cell', () => { + const pivotGrid = fixture.componentInstance.pivotGrid; + spyOn(pivotGrid.cellClick, 'emit').and.callThrough(); + fixture.detectChanges(); + + const cell = pivotGrid.gridAPI.get_cell_by_index(0, 'Bulgaria-UnitsSold') as CellType; + + pivotGrid.cellClick.emit({ cell, event: null }); + cell.nativeElement.click(); + const cellClickargs: IGridCellEventArgs = { cell, event: new MouseEvent('click') }; + + const gridCell = cellClickargs.cell as IgxGridCellComponent; + const firstEntry = gridCell.rowData.aggregationValues.entries().next().value; + expect(firstEntry).toEqual(['USA-UnitsSold', 829]); + }); + }); }); describe('IgxPivotGrid complex hierarchy #pivotGrid', () => { From f9cf56b414d4d9312ac273fe1398cea724981884 Mon Sep 17 00:00:00 2001 From: ttonev Date: Tue, 28 Jan 2025 17:32:19 +0200 Subject: [PATCH 3/4] fix(pivot): added IgxPivotGridRow --- .../src/lib/grids/grid-public-row.ts | 25 +++++++++++++++++++ .../grids/pivot-grid/pivot-grid.component.ts | 4 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid-public-row.ts b/projects/igniteui-angular/src/lib/grids/grid-public-row.ts index 89a2cabe484..5ca1eac6fdc 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-public-row.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-public-row.ts @@ -791,3 +791,28 @@ export class IgxSummaryRow implements RowType { return row; } } + +export class IgxPivotGridRow extends BaseRow { + /** + * @hidden + */ + constructor( + public override grid: GridType, + public override index: number, data?: any + ) { + super(); + this._data = data && data.addRow && data.recordRef ? data.recordRef : data; + } + + /** + * Gets the rendered cells in the row component. + */ + public override get cells(): CellType[] { + const res: CellType[] = []; + this.grid.columns.forEach(col => { + const cell: CellType = new IgxGridCell(this.grid, this.index, col); + res.push(cell); + }); + return res; + } + } diff --git a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts index b5e3bb49694..dd37a0b2ee7 100644 --- a/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts +++ b/projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts @@ -102,7 +102,7 @@ import { IgxTextHighlightService } from '../../directives/text-highlight/text-hi import { IgxPivotRowHeaderGroupComponent } from './pivot-row-header-group.component'; import { IgxPivotDateDimension } from './pivot-grid-dimensions'; import { IgxPivotRowDimensionMrlRowComponent } from './pivot-row-dimension-mrl-row.component'; -import { IgxGridRow } from '../grid-public-row'; +import { IgxPivotGridRow } from '../grid-public-row'; let NEXT_ID = 0; const MINIMUM_COLUMN_WIDTH = 200; @@ -2523,7 +2523,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni if (!row && rec) { - row = new IgxGridRow(this, index, rec); + row = new IgxPivotGridRow(this, index, rec); } return row; } From 44b63725a2a9ab7ff7a22c15dcbab584f1d4d5d8 Mon Sep 17 00:00:00 2001 From: ttonev Date: Thu, 13 Feb 2025 16:58:22 +0200 Subject: [PATCH 4/4] fix(pivot-grid): refactor IgxPivotGridRow to implement RowType --- .../src/lib/grids/grid-public-row.ts | 62 ++++++++++++------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid-public-row.ts b/projects/igniteui-angular/src/lib/grids/grid-public-row.ts index 5ca1eac6fdc..db549a456db 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-public-row.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-public-row.ts @@ -792,27 +792,41 @@ export class IgxSummaryRow implements RowType { } } -export class IgxPivotGridRow extends BaseRow { - /** - * @hidden - */ - constructor( - public override grid: GridType, - public override index: number, data?: any - ) { - super(); - this._data = data && data.addRow && data.recordRef ? data.recordRef : data; - } - - /** - * Gets the rendered cells in the row component. - */ - public override get cells(): CellType[] { - const res: CellType[] = []; - this.grid.columns.forEach(col => { - const cell: CellType = new IgxGridCell(this.grid, this.index, col); - res.push(cell); - }); - return res; - } - } +export class IgxPivotGridRow implements RowType { + public index: number; + public grid: GridType; + private _data?: any; + + constructor(grid: GridType, index: number, data?: any) { + this.grid = grid; + this.index = index; + this._data = data && data.addRow && data.recordRef ? data.recordRef : data; + } + + public get data(): any { + return this._data ?? this.grid.dataView[this.index]; + } + + public get viewIndex(): number { + return this.index + this.grid.page * this.grid.perPage; + } + + public get key(): any { + const data = this._data ?? this.grid.dataView[this.index]; + const primaryKey = this.grid.primaryKey; + return primaryKey ? data[primaryKey] : data; + } + + public get selected(): boolean { + return this.grid.selectionService.isRowSelected(this.key); + } + + public set selected(val: boolean) { + if (val) { + this.grid.selectionService.selectRowsWithNoEvent([this.key]); + } else { + this.grid.selectionService.deselectRowsWithNoEvent([this.key]); + } + this.grid.cdr.markForCheck(); + } +}