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(grid): Process pinned columns and column groups when the columns … #13844

Merged
merged 6 commits into from
Feb 8, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
}
this.children.forEach(child => {
child.parent = this;
if (this.pinned) {
child.pinned = this.pinned;
}
});
if (this.collapsible) {
this.setExpandCollapseState();
Expand All @@ -290,11 +293,22 @@ export class IgxColumnGroupComponent extends IgxColumnComponent implements After
this.children.changes
.pipe(takeUntil(this.destroy$))
.subscribe((change: QueryList<IgxColumnComponent>) => {
change.forEach(x => x.parent = this);
let shouldReinitPinning = false;
change.forEach(x => {
x.parent = this;
if (this.pinned && x.pinned !== this.pinned) {
shouldReinitPinning = true;
x.pinned = this.pinned;
}
});
if (this.collapsible) {
this.setExpandCollapseState();
}
if (shouldReinitPinning) {
(this.grid as any).initPinning();
}
});

}

/** @hidden @internal **/
Expand Down
76 changes: 42 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 @@ -6557,16 +6557,21 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
if (diff) {
let added = false;
let removed = false;
let pinning = false;
diff.forEachAddedItem((record: IterableChangeRecord<IgxColumnComponent>) => {
added = true;
if (record.item.pinned) {
this._pinnedColumns.push(record.item);
pinning = true;
} else {
this._unpinnedColumns.push(record.item);
}
});

this.initColumns(this.columnList.toArray(), (col: IgxColumnComponent) => this.columnInit.emit(col));
if (pinning) {
this.initPinning();
}

diff.forEachRemovedItem((record: IterableChangeRecord<IgxColumnComponent | IgxColumnGroupComponent>) => {
const isColumnGroup = record.item instanceof IgxColumnGroupComponent;
Expand Down Expand Up @@ -7175,42 +7180,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 @@ -7642,4 +7614,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;
}
}
Loading