Skip to content

Commit 0e77305

Browse files
authored
Merge branch 'master' into dpetev/paging-internal-api-refactor
2 parents 639ab4b + b2f08b3 commit 0e77305

File tree

9 files changed

+107
-93
lines changed

9 files changed

+107
-93
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ All notable changes for each version of this project will be documented in this
88
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`:
99
- `GroupMemberCountSortingStrategy` is added, which can be used to sort the grid by number of items in each group in ASC or DESC order, if grouping is applied.
1010
- A new argument `primaryKey` has been introduced to `IRowDataEventArgs` Interface and part of the event arguments that are emitted by the `rowAdded` and `rowDeleted` events. When the grid has a primary key attribute added, then the emitted `primaryKey` event argument represents the row ID, otherwise it defaults to undefined.
11+
- Added the `autoGenerateExclude` property that accepts an array of strings for property names that are to be excluded from the generated column collection
1112
- `IgxColumnComponent`
1213
- Added `currRec` and `groupRec` parameters to the `groupingComparer` function that give access to the all properties of the compared records.
13-
1414
- `IgxOverlayService`
1515
-A new event `contentAppending` is introduced - the event is emitted before the content is appended to the overlay. The event is emitted with `OverlayEventArgs` arguments and is not cancellable.
1616

@@ -19,6 +19,7 @@ All notable changes for each version of this project will be documented in this
1919
- The `IgxPivotDateDimension` properties `inBaseDimension` and `inOption` have been deprecated and renamed to `baseDimension` and `options` respectively.
2020
- `IgxGrid`
2121
- **Breaking Change** The `onGroupingDone` output has been renamed to `groupingDone` to not violate the no on-prefixed outputs convention. Automatic migrations are available and will be applied on `ng update`.
22+
- Column formatters are now applied to values shown group rows when using the default template. For custom formatters, the formatter function is called with the data from the first row in the group.
2223
- `DisplayDensity`
2324
- **Breaking Change** The `onDensityChanged` output has been renamed to `densityChanged` to not violate the no on-prefixed outputs convention. All components exposing this event are affected. Automatic migrations are available and will be applied on `ng update`.
2425
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`

projects/igniteui-angular/migrations/update-15_1_0/changes/members.json

Lines changed: 0 additions & 72 deletions
This file was deleted.

projects/igniteui-angular/src/lib/grids/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Below is the list of all inputs that the developers may set to configure the gri
166166
|`data`|Array|The data source for the grid.|
167167
|`resourceStrings`| IGridResourceStrings | Resource strings of the grid. |
168168
|`autoGenerate`|boolean|Autogenerate grid's columns, default value is _false_|
169+
|`autoGenerateExclude`|Array|A list of property keys to be excluded from the generated column collection, default is _[]_|
169170
|`batchEditing`|boolean|Toggles batch editing in the grid, default is _false_|
170171
|`moving`|boolean|Enables the columns moving feature. Defaults to _false_|
171172
|`paging`|boolean|Enables the paging feature. Defaults to _false_.|

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,23 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
212212
@Input()
213213
public autoGenerate = false;
214214

215+
/**
216+
* Gets/Sets a list of property keys to be excluded from the generated column collection
217+
* @remarks
218+
* The collection is only used during initialization and changing it will not cause any changes in the generated columns at runtime
219+
* unless the grid is destroyed and recreated. To modify the columns visible in the UI at runtime, please use their
220+
* [hidden](https://www.infragistics.com/products/ignite-ui-angular/docs/typescript/latest/classes/IgxColumnComponent.html#hidden) property.
221+
* @example
222+
* ```html
223+
* <igx-grid data=[Data] [autoGenerate]="true" [autoGenerateExclude]="['ProductName', 'Count']"></igx-grid>
224+
* ```
225+
* ```typescript
226+
* const Data = [{ 'Id': '1', 'ProductName': 'name1', 'Description': 'description1', 'Count': 5 }]
227+
* ```
228+
*/
229+
@Input()
230+
public autoGenerateExclude: string[] = [];
231+
215232
/**
216233
* Controls whether columns moving is enabled in the grid.
217234
*
@@ -7159,7 +7176,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
71597176
}
71607177

71617178
protected generateDataFields(data: any[]): string[] {
7162-
return Object.keys(data && data.length !== 0 ? data[0] : []);
7179+
return Object.keys(data && data.length !== 0 ? data[0] : [])
7180+
.filter(key => !this.autoGenerateExclude.includes(key));
71637181
}
71647182

71657183
/**

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ describe('IgxGrid Component Tests #grid', () => {
116116
});
117117
});
118118

119+
it('should skip properties from autoGenerateExclude when auto-generating columns', () => {
120+
const fix = TestBed.createComponent(IgxGridTestComponent);
121+
fix.componentInstance.data = [
122+
{ Number: 1, String: '1', Boolean: true, Date: new Date(Date.now()) }
123+
];
124+
fix.componentInstance.autoGenerateExclude = ['Date', 'String'];
125+
fix.componentInstance.columns = [];
126+
fix.componentInstance.autoGenerate = true;
127+
fix.detectChanges();
128+
const grid = fix.componentInstance.grid;
129+
130+
expect(grid.columns.map(col => col.field)).toEqual(['Number', 'Boolean'], 'Invalid columns after exclusion initialized');
131+
});
132+
119133
it('should initialize a grid and allow changing columns runtime with ngFor', () => {
120134
const fix = TestBed.createComponent(IgxGridTestComponent);
121135
fix.detectChanges();
@@ -2707,7 +2721,7 @@ describe('IgxGrid Component Tests #grid', () => {
27072721

27082722
@Component({
27092723
template: `<div style="width: 800px; height: 600px;">
2710-
<igx-grid #grid [data]="data" [autoGenerate]="autoGenerate" (columnInit)="columnCreated($event)">
2724+
<igx-grid #grid [data]="data" [autoGenerate]="autoGenerate" [autoGenerateExclude]="autoGenerateExclude" (columnInit)="columnCreated($event)">
27112725
<igx-column *ngFor="let column of columns;" [field]="column.field" [hasSummary]="column.hasSummary"
27122726
[header]="column.field" [width]="column.width">
27132727
</igx-column>
@@ -2724,6 +2738,8 @@ export class IgxGridTestComponent {
27242738

27252739
public autoGenerate = false;
27262740

2741+
public autoGenerateExclude = [];
2742+
27272743
public columnEventCount = 0;
27282744

27292745
constructor(public cdr: ChangeDetectorRef) { }

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, ViewChild, TemplateRef, QueryList } from '@angular/core';
2+
import { formatNumber } from '@angular/common'
23
import { fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
34
import { By } from '@angular/platform-browser';
45
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
@@ -788,7 +789,7 @@ describe('IgxGrid - GroupBy #grid', () => {
788789
fix.detectChanges();
789790
grid.groupBy({
790791
fieldName: 'ReleaseDate', dir: SortingDirection.Asc, ignoreCase: false
791-
});
792+
});
792793
fix.detectChanges();
793794
spyOn(grid.groupingExpressionsChange, 'emit');
794795
fix.detectChanges();
@@ -1516,7 +1517,7 @@ describe('IgxGrid - GroupBy #grid', () => {
15161517
expect(GridSelectionFunctions.verifyGroupByRowCheckboxState(grRow, true, false));
15171518
}));
15181519

1519-
it('the group row selector state should be indeterminated if some of the records in the group but not all are selected',
1520+
it('the group row selector state should be undetermined if some of the records in the group but not all are selected',
15201521
fakeAsync(() => {
15211522
const fix = TestBed.createComponent(DefaultGridComponent);
15221523
const grid = fix.componentInstance.instance;
@@ -2088,6 +2089,33 @@ describe('IgxGrid - GroupBy #grid', () => {
20882089
expect(fix.componentInstance.onGroupByRowClick).toHaveBeenCalledWith(fix.componentInstance.groupByRowClick, contextUnselect);
20892090
}));
20902091

2092+
// GroupBy Row Formatting
2093+
it('should properly apply formatters, both custom and default ones for the default row value template', fakeAsync(() => {
2094+
const fix = TestBed.createComponent(GroupableGridComponent);
2095+
const grid = fix.componentInstance.instance;
2096+
tick();
2097+
fix.detectChanges();
2098+
grid.groupBy({
2099+
fieldName: 'Downloads', dir: SortingDirection.Desc, ignoreCase: false
2100+
});
2101+
tick();
2102+
fix.detectChanges();
2103+
let cellText = grid.groupsRowList.first.nativeElement.querySelector(".igx-group-label__text").innerText;
2104+
expect(cellText).toEqual(formatNumber(1000, grid.locale));
2105+
// apply custom formatter
2106+
grid.getColumnByName('Downloads').formatter = (value, _row) => `\$${value}`;
2107+
grid.groupingExpressions = [];
2108+
tick();
2109+
fix.detectChanges();
2110+
grid.groupBy({
2111+
fieldName: 'Downloads', dir: SortingDirection.Desc, ignoreCase: false
2112+
});
2113+
tick();
2114+
fix.detectChanges();
2115+
cellText = grid.groupsRowList.first.nativeElement.querySelector(".igx-group-label__text").innerText;
2116+
expect(cellText).toEqual('$1000');
2117+
}));
2118+
20912119
// GroupBy + Resizing
20922120
it('should retain same size for group row after a column is resized.', fakeAsync(() => {
20932121
const fix = TestBed.createComponent(DefaultGridComponent);
@@ -3819,7 +3847,7 @@ export class CustomTemplateGridComponent extends DataParent {
38193847
public width = '800px';
38203848
public height = null;
38213849

3822-
@ViewChild('template', {read: TemplateRef })
3850+
@ViewChild('template', { read: TemplateRef })
38233851
public customGroupBy: TemplateRef<any>;
38243852
}
38253853

projects/igniteui-angular/src/lib/grids/grid/groupby-row.component.html

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,19 @@
4848
(groupRow.expression ? groupRow.expression.fieldName : '') }}:
4949
</span>
5050

51-
<ng-container *ngIf="dataType === 'boolean' || dataType === 'string'; else default">
52-
<span class="igx-group-label__text">{{ groupRow.value }}</span>
53-
</ng-container>
54-
<ng-template #default>
55-
<ng-container *ngIf="dataType === 'number'">
56-
<span class="igx-group-label__text">{{ groupRow.value | number }}</span>
57-
</ng-container>
58-
<ng-container *ngIf="dataType === 'date' || dataType === 'dateTime' || dataType === 'time'">
59-
<span class="igx-group-label__text">{{ groupRow.value |
60-
date:groupRow.column.pipeArgs.format:groupRow.column.pipeArgs.timezone:grid.locale }}</span>
61-
</ng-container>
62-
</ng-template>
51+
<span class="igx-group-label__text">{{
52+
formatter
53+
? (groupRow.value | columnFormatter:formatter:groupRow.records[0]:null)
54+
: dataType === "number"
55+
? (groupRow.value | number:groupRow.column.pipeArgs.digitsInfo:grid.locale)
56+
: (dataType === 'date' || dataType === 'time' || dataType === 'dateTime')
57+
? (groupRow.value | date:groupRow.column.pipeArgs.format:groupRow.column.pipeArgs.timezone:grid.locale)
58+
: dataType === 'currency'
59+
? (groupRow.value | currency:currencyCode:groupRow.column.pipeArgs.display:groupRow.column.pipeArgs.digitsInfo:grid.locale)
60+
: dataType === 'percent'
61+
? (groupRow.value | percent:groupRow.column.pipeArgs.digitsInfo:grid.locale)
62+
: groupRow.value
63+
}}</span>
6364

6465
<igx-badge [value]="groupRow.records ? groupRow.records.length : 0" class='igx-group-label__count-badge'>
6566
</igx-badge>

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Subject } from 'rxjs';
2121
import { IgxGridRowComponent } from './grid-row.component';
2222
import { GridSelectionMode } from '../common/enums';
2323
import { ISelectionNode } from '../common/types';
24+
import { getLocaleCurrencyCode } from '@angular/common';
2425

2526
@Component({
2627
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -119,6 +120,12 @@ export class IgxGridGroupByRowComponent implements OnDestroy {
119120
return this.isActive();
120121
}
121122

123+
/** @hidden @internal */
124+
public get currencyCode(): string {
125+
return this.groupRow.column.pipeArgs.currencyCode ?
126+
this.groupRow.column.pipeArgs.currencyCode : getLocaleCurrencyCode(this.grid.locale);
127+
}
128+
122129
constructor(
123130
@Inject(IGX_GRID_BASE) public grid: GridType,
124131
public gridSelection: IgxGridSelectionService,
@@ -249,13 +256,21 @@ export class IgxGridGroupByRowComponent implements OnDestroy {
249256
}
250257

251258
/**
252-
* @hidden
253-
*/
259+
* @hidden @internal
260+
*/
254261
public get dataType(): any {
255262
const column = this.groupRow.column;
256263
return (column && column.dataType) || GridColumnDataType.String;
257264
}
258265

266+
/**
267+
* @hidden @internal
268+
*/
269+
public get formatter(): any {
270+
const column = this.groupRow.column;
271+
return (column && column.formatter) || null;
272+
}
273+
259274
/**
260275
* @hidden @internal
261276
*/

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,17 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
369369
public verticalRowDimScrollContainers: QueryList<IgxGridForOfDirective<any>>;
370370

371371
/**
372-
* @hidden @interal
372+
* @hidden @internal
373373
*/
374374
@Input()
375375
public addRowEmptyTemplate: TemplateRef<any>;
376376

377+
/**
378+
* @hidden @internal
379+
*/
380+
@Input()
381+
public autoGenerateExclude: string[] = [];
382+
377383
/**
378384
* @hidden @internal
379385
*/

0 commit comments

Comments
 (0)