Skip to content

Commit e33a1a6

Browse files
authored
fix(grid): Process pinned columns and column groups when the columns … (#13845)
1 parent 85c86c4 commit e33a1a6

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
@@ -282,6 +282,9 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
282282
}
283283
this.children.forEach(child => {
284284
child.parent = this;
285+
if (this.pinned) {
286+
child.pinned = this.pinned;
287+
}
285288
});
286289
if (this.collapsible) {
287290
this.setExpandCollapseState();
@@ -290,11 +293,22 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
290293
this.children.changes
291294
.pipe(takeUntil(this.destroy$))
292295
.subscribe((change: QueryList<IgxColumnComponent>) => {
293-
change.forEach(x => x.parent = this);
296+
let shouldReinitPinning = false;
297+
change.forEach(x => {
298+
x.parent = this;
299+
if (this.pinned && x.pinned !== this.pinned) {
300+
shouldReinitPinning = true;
301+
x.pinned = this.pinned;
302+
}
303+
});
294304
if (this.collapsible) {
295305
this.setExpandCollapseState();
296306
}
307+
if (shouldReinitPinning) {
308+
(this.grid as any).initPinning();
309+
}
297310
});
311+
298312
}
299313

300314
/** @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
@@ -6533,16 +6533,21 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
65336533
if (diff) {
65346534
let added = false;
65356535
let removed = false;
6536+
let pinning = false;
65366537
diff.forEachAddedItem((record: IterableChangeRecord<IgxColumnComponent>) => {
65376538
added = true;
65386539
if (record.item.pinned) {
65396540
this._pinnedColumns.push(record.item);
6541+
pinning = true;
65406542
} else {
65416543
this._unpinnedColumns.push(record.item);
65426544
}
65436545
});
65446546

65456547
this.initColumns(this.columnList.toArray(), (col: IgxColumnComponent) => this.columnInit.emit(col));
6548+
if (pinning) {
6549+
this.initPinning();
6550+
}
65466551

65476552
diff.forEachRemovedItem((record: IterableChangeRecord<IgxColumnComponent | IgxColumnGroupComponent>) => {
65486553
const isColumnGroup = record.item instanceof IgxColumnGroupComponent;
@@ -7151,42 +7156,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
71517156
* @hidden
71527157
*/
71537158
protected initPinning() {
7154-
const pinnedColumns = [];
7155-
const unpinnedColumns = [];
7156-
71577159
this.calculateGridWidth();
71587160
this.resetCaches();
7159-
// When a column is a group or is inside a group, pin all related.
7160-
this._pinnedColumns.forEach(col => {
7161-
if (col.parent) {
7162-
col.parent.pinned = true;
7163-
}
7164-
if (col.columnGroup) {
7165-
col.children.forEach(child => child.pinned = true);
7166-
}
7167-
});
7168-
7169-
// Make sure we don't exceed unpinned area min width and get pinned and unpinned col collections.
7170-
// We take into account top level columns (top level groups and non groups).
7171-
// If top level is unpinned the pinning handles all children to be unpinned as well.
7172-
for (const column of this._columns) {
7173-
if (column.pinned && !column.parent) {
7174-
pinnedColumns.push(column);
7175-
} else if (column.pinned && column.parent) {
7176-
if (column.topLevelParent.pinned) {
7177-
pinnedColumns.push(column);
7178-
} else {
7179-
column.pinned = false;
7180-
unpinnedColumns.push(column);
7181-
}
7182-
} else {
7183-
unpinnedColumns.push(column);
7184-
}
7185-
}
7186-
7187-
// Assign the applicable collections.
7188-
this._pinnedColumns = pinnedColumns;
7189-
this._unpinnedColumns = unpinnedColumns;
7161+
this.handleColumnPinningForGroups();
71907162
this.notifyChanges();
71917163
}
71927164

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

0 commit comments

Comments
 (0)