Skip to content

Commit dbd78cf

Browse files
committed
Merge remote-tracking branch 'remotes/origin/master' into mvenkov/remove-internal-overlay-outlets
2 parents fd142ac + 58e6489 commit dbd78cf

6 files changed

Lines changed: 98 additions & 21 deletions

File tree

projects/igniteui-angular/core/src/data-operations/merge-strategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class DefaultMergeStrategy implements IGridMergeStrategy {
7474
index++;
7575
continue;
7676
}
77-
const recToUpdateData = recData ?? { recordRef: grid.isGhostRecord(rec) ? rec.recordRef : rec, cellMergeMeta: new Map<string, IMergeByResult>(), ghostRecord: rec.ghostRecord };
77+
const recToUpdateData = recData ?? { recordRef: grid.isGhostRecord(rec) ? rec.recordRef : rec, cellMergeMeta: new Map<string, IMergeByResult>(), ghostRecord: rec.ghostRecord, index: index };
7878
recToUpdateData.cellMergeMeta.set(field, { rowSpan: 1, childRecords: [] });
7979
if (prev && comparer.call(this, prev.recordRef, recToUpdateData.recordRef, field, isDate, isTime) && prev.ghostRecord === recToUpdateData.ghostRecord) {
8080
const root = prev.cellMergeMeta.get(field)?.root ?? prev;

projects/igniteui-angular/directives/src/directives/for-of/for_of.directive.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,11 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
275275
protected _differ: IterableDiffer<T> | null = null;
276276
protected _trackByFn: TrackByFunction<T>;
277277
protected individualSizeCache: number[] = [];
278+
/**
279+
* @hidden
280+
*/
278281
/** Internal track for scroll top that is being virtualized */
279-
protected _virtScrollPosition = 0;
282+
public _virtScrollPosition = 0;
280283
/** If the next onScroll event is triggered due to internal setting of scrollTop */
281284
protected _bScrollInternal = false;
282285
// End properties related to virtual height handling
@@ -901,7 +904,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
901904
const maxVirtScrollTop = this._virtSize - containerSize;
902905
this._bScrollInternal = true;
903906
this._virtScrollPosition = maxVirtScrollTop;
904-
this.scrollPosition = maxVirtScrollTop;
907+
this.scrollPosition = maxVirtScrollTop / this._virtRatio;
905908
return;
906909
}
907910
if (this._adjustToIndex) {
@@ -1529,11 +1532,12 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U
15291532
let currentScroll = this.scrollPosition;
15301533
if (this._virtRatio !== 1) {
15311534
this._calcVirtualScrollPosition(this.scrollPosition);
1532-
currentScroll = this._virtScrollPosition;
1535+
scrollOffset = this.fixedUpdateAllElements(this._virtScrollPosition);
1536+
} else {
1537+
const scroll = this.scrollComponent.nativeElement;
1538+
scrollOffset = scroll && this.scrollComponent.size ?
1539+
currentScroll - this.sizesCache[this.state.startIndex] : 0;
15331540
}
1534-
const scroll = this.scrollComponent.nativeElement;
1535-
scrollOffset = scroll && this.scrollComponent.size ?
1536-
currentScroll - this.sizesCache[this.state.startIndex] : 0;
15371541
const dir = this.igxForScrollOrientation === 'horizontal' ? 'left' : 'transform';
15381542
this.dc.instance._viewContainer.element.nativeElement.style[dir] = this.igxForScrollOrientation === 'horizontal' ?
15391543
-(scrollOffset) + 'px' :

projects/igniteui-angular/grids/grid/src/grid-add-row.spec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { TestBed, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
44
import { DebugElement } from '@angular/core';
55
import { GridFunctions, GridSummaryFunctions } from '../../../test-utils/grid-functions.spec';
66
import {
7-
IgxAddRowComponent, IgxGridRowEditingDefinedColumnsComponent, IgxGridRowEditingTransactionComponent
7+
IgxAddRowComponent, IgxGridRowEditingDefinedColumnsComponent, IgxGridRowEditingTransactionComponent,
8+
GridDynamicActionStripComponent
89
} from '../../../test-utils/grid-samples.spec';
910

1011
import { By } from '@angular/platform-browser';
@@ -45,7 +46,8 @@ describe('IgxGrid - Row Adding #grid', () => {
4546
IgxGridRowEditingTransactionComponent,
4647
IgxGridRowEditingDefinedColumnsComponent,
4748
ColumnLayoutTestComponent,
48-
DefaultGridMasterDetailComponent
49+
DefaultGridMasterDetailComponent,
50+
GridDynamicActionStripComponent
4951
],
5052
providers: [
5153
IgxGridMRLNavigationService
@@ -1121,4 +1123,28 @@ describe('IgxGrid - Row Adding #grid', () => {
11211123
expect(grid.rowChangesCount).toEqual(3);
11221124
});
11231125
});
1126+
1127+
describe('ActionStrip - Dynamic Addition', () => {
1128+
beforeEach(() => {
1129+
fixture = TestBed.createComponent(GridDynamicActionStripComponent);
1130+
fixture.detectChanges();
1131+
grid = fixture.componentInstance.grid;
1132+
});
1133+
1134+
it('Should set outlet for actionstrip menu when added post-init', async () => {
1135+
// Verify no actionstrip initially
1136+
expect(fixture.componentInstance.actionStrip).toBeUndefined();
1137+
expect(grid.actionStrip).toBeUndefined();
1138+
1139+
// Add the actionstrip dynamically
1140+
fixture.componentInstance.showActionStrip = true;
1141+
fixture.detectChanges();
1142+
await wait(16);
1143+
1144+
// Get reference to the actionstrip
1145+
actionStrip = fixture.componentInstance.actionStrip;
1146+
expect(actionStrip).toBeDefined();
1147+
expect(grid.actionStrip).toBeDefined();
1148+
});
1149+
});
11241150
});

projects/igniteui-angular/grids/grid/src/grid-base.directive.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3637,7 +3637,7 @@ export abstract class IgxGridBaseDirective implements GridType,
36373637

36383638
protected getMergeCellOffset(rowData) {
36393639
const index = rowData.dataIndex;
3640-
let offset = this.verticalScrollContainer.scrollPosition - this.verticalScrollContainer.getScrollForIndex(index);
3640+
let offset = this.verticalScrollContainer._virtScrollPosition - this.verticalScrollContainer.getScrollForIndex(index);
36413641
if (this.hasPinnedRecords && this.isRowPinningToTop) {
36423642
offset -= this.pinnedRowHeight;
36433643
}
@@ -4044,7 +4044,6 @@ export abstract class IgxGridBaseDirective implements GridType,
40444044
});
40454045
}
40464046

4047-
40484047
protected get activeRowIndexes(): number[] {
40494048
if (this._activeRowIndexes) {
40504049
return this._activeRowIndexes;
@@ -8194,16 +8193,16 @@ export abstract class IgxGridBaseDirective implements GridType,
81948193
// recalc merged data
81958194
if (this.columnsToMerge.length > 0) {
81968195
const startIndex = this.verticalScrollContainer.state.startIndex;
8197-
const prevDataView = this.verticalScrollContainer.igxForOf?.slice(0, startIndex);
81988196
const data = [];
8199-
for (let index = 0; index < startIndex; index++) {
8200-
const rec = prevDataView[index];
8201-
if (rec.cellMergeMeta &&
8202-
// index + maxRowSpan is within view
8203-
startIndex < (index + Math.max(...rec.cellMergeMeta.values().toArray().map(x => x.rowSpan)))) {
8204-
const visibleIndex = this.isRowPinningToTop ? index + this.pinnedRecordsCount : index;
8205-
data.push({ record: rec, index: visibleIndex, dataIndex: index });
8206-
}
8197+
const rec = this.verticalScrollContainer.igxForOf[startIndex];
8198+
if (rec && rec.cellMergeMeta) {
8199+
this.columnsToMerge.forEach((col) => {
8200+
const root = rec.cellMergeMeta?.get(col.field)?.root;
8201+
if (root) {
8202+
data.push({ record: root, index: root.index, dataIndex: root.index });
8203+
}
8204+
})
8205+
82078206
}
82088207
this._mergedDataInView = data;
82098208
this.notifyChanges();

projects/igniteui-angular/grids/grid/src/grid.pipes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class IgxGridUnmergeActivePipe implements PipeTransform {
121121

122122
const result = cloneArray(collection) as any;
123123
uniqueRoots.forEach(x => {
124-
const index = collection.indexOf(x);
124+
const index = x.index;
125125
const colKeys = [...x.cellMergeMeta.keys()];
126126
const cols = colsToMerge.filter(col => colKeys.indexOf(col.field) !== -1);
127127
for (const col of cols) {

projects/igniteui-angular/test-utils/grid-samples.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,54 @@ export class IgxAddRowComponent implements OnInit {
24192419
}
24202420
}
24212421

2422+
@Component({
2423+
template: `
2424+
<igx-grid #grid [data]="data" [width]="'800px'" [height]="'500px'"
2425+
[rowEditable]="true" [primaryKey]="'ID'">
2426+
@for (c of columns; track c.field) {
2427+
<igx-column [field]="c.field" [header]="c.field" [width]="c.width"></igx-column>
2428+
}
2429+
2430+
@if (showActionStrip) {
2431+
<igx-action-strip #actionStrip>
2432+
<igx-grid-editing-actions [addRow]='true'></igx-grid-editing-actions>
2433+
</igx-action-strip>
2434+
}
2435+
</igx-grid>
2436+
`,
2437+
imports: [
2438+
IgxGridComponent,
2439+
IgxColumnComponent,
2440+
IgxActionStripComponent,
2441+
IgxGridEditingActionsComponent
2442+
]
2443+
})
2444+
export class GridDynamicActionStripComponent implements OnInit {
2445+
@ViewChild('actionStrip', { read: IgxActionStripComponent })
2446+
public actionStrip: IgxActionStripComponent;
2447+
2448+
@ViewChild('grid', { read: IgxGridComponent, static: true })
2449+
public grid: IgxGridComponent;
2450+
2451+
public data: any[];
2452+
public columns: any[];
2453+
public showActionStrip = false;
2454+
2455+
public ngOnInit() {
2456+
this.columns = [
2457+
{ field: 'ID', width: '200px' },
2458+
{ field: 'CompanyName', width: '200px' },
2459+
{ field: 'ContactName', width: '200px' }
2460+
];
2461+
2462+
this.data = [
2463+
{ ID: 'ALFKI', CompanyName: 'Alfreds Futterkiste', ContactName: 'Maria Anders' },
2464+
{ ID: 'ANATR', CompanyName: 'Ana Trujillo Emparedados y helados', ContactName: 'Ana Trujillo' },
2465+
{ ID: 'ANTON', CompanyName: 'Antonio Moreno Taquería', ContactName: 'Antonio Moreno' }
2466+
];
2467+
}
2468+
}
2469+
24222470
@Component({
24232471
template: GridTemplateStrings.declareGrid(` [hideGroupedColumns]="true"`, '', ColumnDefinitions.exportGroupedDataColumns),
24242472
imports: [IgxGridComponent, IgxColumnComponent]

0 commit comments

Comments
 (0)