Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pivot-grid): added createRow method for grid based events #15209

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 '../grid-public-row';

let NEXT_ID = 0;
const MINIMUM_COLUMN_WIDTH = 200;
Expand Down Expand Up @@ -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);
Copy link
Member

@skrustev skrustev Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the IgxGridRow is a good representation of the PivotRow. It has a lot of setters and getters that should be removed that are not relevant if you look at the IgxPivotRowComponent. I think a new IgxPivotGridRow class should be introduced in this case.

}
return row;
}
}
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down
Loading