Skip to content

Commit 292ece3

Browse files
ChronosSFkdinev
andauthored
feat(grid): add a property to filter out columns from autogen (#12748)
* feat(grid): add a property to filter out columns from autogen * chore(*): removing pivot implementation as it's not needed * chore(*): addressing review comment * chore(*): addressing comments --------- Co-authored-by: Konstantin Dinev <[email protected]>
1 parent 21d68ee commit 292ece3

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 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

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
*
@@ -7145,7 +7162,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
71457162
}
71467163

71477164
protected generateDataFields(data: any[]): string[] {
7148-
return Object.keys(data && data.length !== 0 ? data[0] : []);
7165+
return Object.keys(data && data.length !== 0 ? data[0] : [])
7166+
.filter(key => !this.autoGenerateExclude.includes(key));
71497167
}
71507168

71517169
/**

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/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)