Skip to content

Commit c39438c

Browse files
authored
Merge pull request #12202 from IgniteUI/mkirova/expose-excel-filtering-template
feat(igxGrid): Add excel style filter template and group row template inputs.
2 parents 92bd943 + aa16caa commit c39438c

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ All notable changes for each version of this project will be documented in this
77
### New Features
88
- `igxGrid` - exposing new Input properties:
99

10+
- `excelStyleHeaderIconTemplate` - Gets/Sets the excel style header icon.
11+
- `groupRowTemplate` - Gets/Sets the template reference for the group row.
1012
- `headSelectorTemplate` - Gets/Sets the header row selector template.
1113
- `rowSelectorTemplate` - Gets/Sets the custom template used for row selectors.
1214
- `groupByRowSelectorTemplate` - Gets/Sets the custom template used for the group row selectors.

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,32 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
14721472
* The custom template, if any, that should be used when rendering a row expand indicator.
14731473
*/
14741474
@ContentChild(IgxExcelStyleHeaderIconDirective, { read: TemplateRef })
1475-
public excelStyleHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1475+
public excelStyleHeaderIconDirectiveTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1476+
1477+
/**
1478+
* Gets the excel style header icon.
1479+
*/
1480+
@Input()
1481+
public get excelStyleHeaderIconTemplate(): TemplateRef<IgxGridHeaderTemplateContext> {
1482+
return this._excelStyleHeaderIconTemplate || this.excelStyleHeaderIconDirectiveTemplate;
1483+
}
1484+
1485+
/**
1486+
* Sets the excel style header icon.
1487+
*```html
1488+
*<ng-template #template igxExcelStyleHeaderIcon>
1489+
* <igx-icon>filter_alt</igx-icon>
1490+
*</ng-template>
1491+
* ```
1492+
*```typescript
1493+
* @ViewChild('template', {read: TemplateRef })
1494+
* public template: TemplateRef<any>;
1495+
* this.grid.excelStyleHeaderIconTemplate = this.template;
1496+
* ```
1497+
*/
1498+
public set excelStyleHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1499+
this._excelStyleHeaderIconTemplate = template;
1500+
}
14761501

14771502

14781503
/**
@@ -3069,6 +3094,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
30693094
private _filteredSortedData = null;
30703095

30713096
private _customDragIndicatorIconTemplate: TemplateRef<IgxGridEmptyTemplateContext>;
3097+
private _excelStyleHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext>;
30723098
private _rowSelectorTemplate: TemplateRef<IgxRowSelectorTemplateContext>;
30733099
private _headSelectorTemplate: TemplateRef<IgxHeadSelectorTemplateContext>;
30743100
private _rowEditTextTemplate: TemplateRef<IgxGridRowEditTextTemplateContext>;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5852,6 +5852,16 @@ describe('IgxGrid - Filtering actions - Excel style filtering #grid', () => {
58525852
expect(icon).not.toBeNull();
58535853
expect(icon.nativeElement.textContent.toLowerCase().trim()).toBe('filter_alt');
58545854
}));
5855+
5856+
it('should allow setting excel style filter icon via Input.', () => {
5857+
grid.excelStyleHeaderIconTemplate = fix.componentInstance.customExcelHeaderIcon;
5858+
fix.detectChanges();
5859+
const header = GridFunctions.getColumnHeader('AnotherField', fix);
5860+
fix.detectChanges();
5861+
const icon = GridFunctions.getHeaderFilterIcon(header);
5862+
fix.detectChanges();
5863+
expect(icon.nativeElement.textContent.toLowerCase().trim()).toBe('search');
5864+
});
58555865
});
58565866

58575867
describe('Load values on demand', () => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
656656
* this.grid.groupRowTemplate = myRowTemplate;
657657
* ```
658658
*/
659+
@Input()
659660
public get groupRowTemplate(): TemplateRef<IgxGroupByRowTemplateContext> {
660661
return this._groupRowTemplate;
661662
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,19 @@ describe('IgxGrid - GroupBy #grid', () => {
591591

592592
}));
593593

594+
it('should allow setting custom template for group row via Input.', fakeAsync(() => {
595+
const fix = TestBed.createComponent(CustomTemplateGridComponent);
596+
const grid = fix.componentInstance.instance;
597+
fix.detectChanges();
598+
grid.groupRowTemplate = fix.componentInstance.customGroupBy;
599+
fix.detectChanges();
600+
grid.groupBy({ fieldName: 'Released', dir: SortingDirection.Desc, ignoreCase: false });
601+
fix.detectChanges();
602+
const grRow = grid.groupsRowList.toArray()[0];
603+
const elem = grRow.groupContent.nativeElement;
604+
expect(elem.innerText.trim()).toEqual('CUSTOM GROUP BY');
605+
}));
606+
594607
it('should have the correct ARIA attributes on the group rows.', fakeAsync(() => {
595608
const fix = TestBed.createComponent(DefaultGridComponent);
596609
const grid = fix.componentInstance.instance;
@@ -3637,6 +3650,11 @@ export class GroupableGridComponent extends DataParent {
36373650
<span>COLLAPSED</span>
36383651
</ng-template>
36393652
</igx-grid>
3653+
<ng-template #template igxGroupByRow let-groupRow>
3654+
<span>
3655+
CUSTOM GROUP BY
3656+
</span>
3657+
</ng-template>
36403658
`
36413659
})
36423660
export class CustomTemplateGridComponent extends DataParent {
@@ -3645,6 +3663,9 @@ export class CustomTemplateGridComponent extends DataParent {
36453663

36463664
public width = '800px';
36473665
public height = null;
3666+
3667+
@ViewChild('template', {read: TemplateRef })
3668+
public customGroupBy: TemplateRef<any>;
36483669
}
36493670

36503671
@Component({

projects/igniteui-angular/src/lib/test-utils/grid-samples.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,13 +1290,19 @@ export class IgxGridFilteringESFEmptyTemplatesComponent extends BasicGridCompone
12901290
<igx-excel-style-search></igx-excel-style-search>
12911291
</igx-excel-style-filter-operations>
12921292
</igx-grid-excel-style-filtering>
1293-
</igx-grid>`
1293+
</igx-grid>
1294+
<ng-template #template igxExcelStyleHeaderIcon>
1295+
<igx-icon>search</igx-icon>
1296+
</ng-template>
1297+
`
12941298
})
12951299
export class IgxGridFilteringESFTemplatesComponent extends BasicGridComponent {
12961300
public customFilter = CustomFilter.instance();
12971301
public resizable = false;
12981302
public filterable = true;
12991303
public data = SampleTestData.excelFilteringData();
1304+
@ViewChild('template', {read: TemplateRef })
1305+
public customExcelHeaderIcon: TemplateRef<any>;
13001306
}
13011307

13021308
@Component({

0 commit comments

Comments
 (0)