Skip to content

Commit b5a4acf

Browse files
authored
Merge branch '8.2.x' into tzhelev/fix-5886-8.2.x
2 parents 56834cd + c0ba115 commit b5a4acf

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

projects/igniteui-angular/src/lib/grids/grid/grid.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
592592
* @memberof IgxGridComponent
593593
*/
594594
public groupBy(expression: IGroupingExpression | Array<IGroupingExpression>): void {
595+
if (this.checkIfNoColumnField(expression)) {
596+
return;
597+
}
595598
this.endEdit(true);
596599
if (expression instanceof Array) {
597600
this._gridAPI.groupBy_multiple(expression);
@@ -992,4 +995,17 @@ export class IgxGridComponent extends IgxGridBaseComponent implements IGridDataB
992995
this.navigation.grid = this;
993996
}
994997
}
998+
999+
private checkIfNoColumnField(expression: IGroupingExpression | Array<IGroupingExpression> | any): boolean {
1000+
if (expression instanceof Array) {
1001+
for (const singleExpression of expression) {
1002+
if (!singleExpression.fieldName) {
1003+
return true;
1004+
}
1005+
}
1006+
return false;
1007+
}
1008+
return !expression.fieldName;
1009+
}
1010+
9951011
}

projects/igniteui-angular/src/lib/grids/grid/grid.directives.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class IgxGroupAreaDropDirective extends IgxDropDirective {
7878
}
7979
const grid = <IgxGridComponent>column.grid;
8080
const isGrouped = grid.groupingExpressions.findIndex((item) => item.fieldName === column.field) !== -1;
81-
if (column.groupable && !isGrouped && !column.columnGroup) {
81+
if (column.groupable && !isGrouped && !column.columnGroup && !!column.field) {
8282
drag.icon.innerText = 'group_work';
8383
this.hovered = true;
8484
} else {
@@ -106,7 +106,7 @@ export class IgxGroupAreaDropDirective extends IgxDropDirective {
106106
}
107107
const grid = <IgxGridComponent>column.grid;
108108
const isGrouped = grid.groupingExpressions.findIndex((item) => item.fieldName === column.field) !== -1;
109-
if (column.groupable && !isGrouped && !column.columnGroup) {
109+
if (column.groupable && !isGrouped && !column.columnGroup && !!column.field) {
110110
grid.groupBy({ fieldName: column.field, dir: SortingDirection.Asc, ignoreCase: column.sortingIgnoreCase,
111111
strategy: column.sortStrategy, groupingComparer: column.groupingComparer });
112112
}

projects/igniteui-angular/src/lib/grids/grid/grid.groupby.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('IgxGrid - GroupBy #grid', () => {
4040
GroupableGridComponent,
4141
CustomTemplateGridComponent,
4242
GroupByDataMoreColumnsComponent,
43+
GroupByEmptyColumnFieldComponent,
4344
MultiColumnHeadersWithGroupingComponent
4445
],
4546
imports: [NoopAnimationsModule, IgxGridModule]
@@ -2026,6 +2027,19 @@ describe('IgxGrid - GroupBy #grid', () => {
20262027
expect(m).toBe('Maximum amount of grouped columns is 10.');
20272028
}));
20282029

2030+
it('should not allow grouping by column with no name', fakeAsync(() => {
2031+
const fix = TestBed.createComponent(GroupByEmptyColumnFieldComponent);
2032+
const grid = fix.componentInstance.instance;
2033+
fix.detectChanges();
2034+
tick();
2035+
const expr = grid.columns.map(val => {
2036+
return { fieldName: val.field, dir: SortingDirection.Asc, ignoreCase: true };
2037+
});
2038+
grid.groupBy(expr);
2039+
tick();
2040+
expect(grid.groupsRowList.toArray().length).toBe(0);
2041+
}));
2042+
20292043
it('should display column header text in the grouping chip.', fakeAsync(() => {
20302044
const fix = TestBed.createComponent(DefaultGridComponent);
20312045
const grid = fix.componentInstance.instance;
@@ -2741,5 +2755,25 @@ export class GroupByDataMoreColumnsComponent extends DataParent {
27412755
public instance: IgxGridComponent;
27422756
}
27432757

2758+
@Component({
2759+
template: `
2760+
<igx-grid
2761+
[width]='width'
2762+
[autoGenerate]='false'
2763+
[data]='data'>
2764+
<igx-column [width]='width' [groupable]='true'>
2765+
<ng-template igxCell>
2766+
<button>Dummy button</button>
2767+
</ng-template>
2768+
</igx-column>
2769+
</igx-grid>
2770+
`
2771+
})
2772+
export class GroupByEmptyColumnFieldComponent extends DataParent {
2773+
public width = '200px';
2774+
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
2775+
public instance: IgxGridComponent;
2776+
}
2777+
27442778
export class CustomSortingStrategy extends DefaultSortingStrategy {
27452779
}

0 commit comments

Comments
 (0)