Skip to content

Commit

Permalink
fix(grid): Process pinned columns and column groups when the columns …
Browse files Browse the repository at this point in the history
…are dynamically rendered ot the collection is changed
  • Loading branch information
mddragnev committed Jan 29, 2024
1 parent 0324a6b commit 6b7c4c5
Showing 1 changed file with 38 additions and 34 deletions.
72 changes: 38 additions & 34 deletions projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6550,6 +6550,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
});

this.initColumns(this.columnList.toArray(), (col: IgxColumnComponent) => this.columnInit.emit(col));
this.handleColumnPinningForGroups();

diff.forEachRemovedItem((record: IterableChangeRecord<IgxColumnComponent | IgxColumnGroupComponent>) => {
const isColumnGroup = record.item instanceof IgxColumnGroupComponent;
Expand Down Expand Up @@ -7158,42 +7159,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
* @hidden
*/
protected initPinning() {
const pinnedColumns = [];
const unpinnedColumns = [];

this.calculateGridWidth();
this.resetCaches();
// When a column is a group or is inside a group, pin all related.
this._pinnedColumns.forEach(col => {
if (col.parent) {
col.parent.pinned = true;
}
if (col.columnGroup) {
col.children.forEach(child => child.pinned = true);
}
});

// Make sure we don't exceed unpinned area min width and get pinned and unpinned col collections.
// We take into account top level columns (top level groups and non groups).
// If top level is unpinned the pinning handles all children to be unpinned as well.
for (const column of this._columns) {
if (column.pinned && !column.parent) {
pinnedColumns.push(column);
} else if (column.pinned && column.parent) {
if (column.topLevelParent.pinned) {
pinnedColumns.push(column);
} else {
column.pinned = false;
unpinnedColumns.push(column);
}
} else {
unpinnedColumns.push(column);
}
}

// Assign the applicable collections.
this._pinnedColumns = pinnedColumns;
this._unpinnedColumns = unpinnedColumns;
this.handleColumnPinningForGroups();
this.notifyChanges();
}

Expand Down Expand Up @@ -7625,4 +7593,40 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
settings.target = targetRow.element.nativeElement;
this.toggleRowEditingOverlay(true);
}

private handleColumnPinningForGroups(): void {
// When a column is a group or is inside a group, pin all related.
const pinnedColumns = [];
const unpinnedColumns = [];

this._pinnedColumns.forEach(col => {
if (col.parent) {
col.parent.pinned = true;
}
if (col.columnGroup) {
col.children.forEach(child => child.pinned = true);
}
});

// Make sure we don't exceed unpinned area min width and get pinned and unpinned col collections.
// We take into account top level columns (top level groups and non groups).
// If top level is unpinned the pinning handles all children to be unpinned as well.
for (const column of this._columns) {
if (column.pinned && !column.parent) {
pinnedColumns.push(column);
} else if (column.pinned && column.parent) {
if (column.topLevelParent.pinned) {
pinnedColumns.push(column);
} else {
column.pinned = false;
unpinnedColumns.push(column);
}
} else {
unpinnedColumns.push(column);
}
}
// Assign the applicable collections.
this._pinnedColumns = pinnedColumns;
this._unpinnedColumns = unpinnedColumns;
}
}

0 comments on commit 6b7c4c5

Please sign in to comment.