Skip to content

Commit cd4856f

Browse files
authored
fix(grid): Process pinned columns and column groups when the columns … (#13846)
1 parent 9831fcc commit cd4856f

File tree

2 files changed

+57
-35
lines changed

2 files changed

+57
-35
lines changed

projects/igniteui-angular/src/lib/grids/columns/column-group.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
281281
}
282282
this.children.forEach(child => {
283283
child.parent = this;
284+
if (this.pinned) {
285+
child.pinned = this.pinned;
286+
}
284287
});
285288
if (this.collapsible) {
286289
this.setExpandCollapseState();
@@ -289,11 +292,22 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
289292
this.children.changes
290293
.pipe(takeUntil(this.destroy$))
291294
.subscribe((change: QueryList<IgxColumnComponent>) => {
292-
change.forEach(x => x.parent = this);
295+
let shouldReinitPinning = false;
296+
change.forEach(x => {
297+
x.parent = this;
298+
if (this.pinned && x.pinned !== this.pinned) {
299+
shouldReinitPinning = true;
300+
x.pinned = this.pinned;
301+
}
302+
});
293303
if (this.collapsible) {
294304
this.setExpandCollapseState();
295305
}
306+
if (shouldReinitPinning) {
307+
(this.grid as any).initPinning();
308+
}
296309
});
310+
297311
}
298312

299313
/** @hidden @internal **/

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

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6540,16 +6540,21 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
65406540
if (diff) {
65416541
let added = false;
65426542
let removed = false;
6543+
let pinning = false;
65436544
diff.forEachAddedItem((record: IterableChangeRecord<IgxColumnComponent>) => {
65446545
added = true;
65456546
if (record.item.pinned) {
65466547
this._pinnedColumns.push(record.item);
6548+
pinning = true;
65476549
} else {
65486550
this._unpinnedColumns.push(record.item);
65496551
}
65506552
});
65516553

65526554
this.initColumns(this.columnList.toArray(), (col: IgxColumnComponent) => this.columnInit.emit(col));
6555+
if (pinning) {
6556+
this.initPinning();
6557+
}
65536558

65546559
diff.forEachRemovedItem((record: IterableChangeRecord<IgxColumnComponent | IgxColumnGroupComponent>) => {
65556560
const isColumnGroup = record.item instanceof IgxColumnGroupComponent;
@@ -7158,42 +7163,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
71587163
* @hidden
71597164
*/
71607165
protected initPinning() {
7161-
const pinnedColumns = [];
7162-
const unpinnedColumns = [];
7163-
71647166
this.calculateGridWidth();
71657167
this.resetCaches();
7166-
// When a column is a group or is inside a group, pin all related.
7167-
this._pinnedColumns.forEach(col => {
7168-
if (col.parent) {
7169-
col.parent.pinned = true;
7170-
}
7171-
if (col.columnGroup) {
7172-
col.children.forEach(child => child.pinned = true);
7173-
}
7174-
});
7175-
7176-
// Make sure we don't exceed unpinned area min width and get pinned and unpinned col collections.
7177-
// We take into account top level columns (top level groups and non groups).
7178-
// If top level is unpinned the pinning handles all children to be unpinned as well.
7179-
for (const column of this._columns) {
7180-
if (column.pinned && !column.parent) {
7181-
pinnedColumns.push(column);
7182-
} else if (column.pinned && column.parent) {
7183-
if (column.topLevelParent.pinned) {
7184-
pinnedColumns.push(column);
7185-
} else {
7186-
column.pinned = false;
7187-
unpinnedColumns.push(column);
7188-
}
7189-
} else {
7190-
unpinnedColumns.push(column);
7191-
}
7192-
}
7193-
7194-
// Assign the applicable collections.
7195-
this._pinnedColumns = pinnedColumns;
7196-
this._unpinnedColumns = unpinnedColumns;
7168+
this.handleColumnPinningForGroups();
71977169
this.notifyChanges();
71987170
}
71997171

@@ -7625,4 +7597,40 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
76257597
settings.target = targetRow.element.nativeElement;
76267598
this.toggleRowEditingOverlay(true);
76277599
}
7600+
7601+
private handleColumnPinningForGroups(): void {
7602+
// When a column is a group or is inside a group, pin all related.
7603+
const pinnedColumns = [];
7604+
const unpinnedColumns = [];
7605+
7606+
this._pinnedColumns.forEach(col => {
7607+
if (col.parent) {
7608+
col.parent.pinned = true;
7609+
}
7610+
if (col.columnGroup) {
7611+
col.children.forEach(child => child.pinned = true);
7612+
}
7613+
});
7614+
7615+
// Make sure we don't exceed unpinned area min width and get pinned and unpinned col collections.
7616+
// We take into account top level columns (top level groups and non groups).
7617+
// If top level is unpinned the pinning handles all children to be unpinned as well.
7618+
for (const column of this._columns) {
7619+
if (column.pinned && !column.parent) {
7620+
pinnedColumns.push(column);
7621+
} else if (column.pinned && column.parent) {
7622+
if (column.topLevelParent.pinned) {
7623+
pinnedColumns.push(column);
7624+
} else {
7625+
column.pinned = false;
7626+
unpinnedColumns.push(column);
7627+
}
7628+
} else {
7629+
unpinnedColumns.push(column);
7630+
}
7631+
}
7632+
// Assign the applicable collections.
7633+
this._pinnedColumns = pinnedColumns;
7634+
this._unpinnedColumns = unpinnedColumns;
7635+
}
76287636
}

0 commit comments

Comments
 (0)