Skip to content

Commit fb4a368

Browse files
authored
Merge branch 'master' into mkirova/expose-excel-filtering-template
2 parents 28d464c + 8d6f31c commit fb4a368

File tree

5 files changed

+149
-7
lines changed

5 files changed

+149
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ All notable changes for each version of this project will be documented in this
66

77
### New Features
88
- `igxGrid` - exposing new Input properties:
9+
910
- `excelStyleHeaderIconTemplate` - Gets/Sets the excel style header icon.
1011
- `groupRowTemplate` - Gets/Sets the template reference for the group row.
12+
- `sortHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are not sorted.
13+
- `sortAscendingHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in asc order.
14+
- `sortDescendingHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in desc order.
1115
- `rowEditActionsTemplate` - Gets/Sets the row edit actions template.
1216
- `rowAddTextTemplate` - Gets/Sets the row add text template.
1317
- `rowEditTextTemplate` - Gets/Sets the row edit text template.

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

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,23 +1499,99 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
14991499
this._excelStyleHeaderIconTemplate = template;
15001500
}
15011501

1502+
15021503
/**
1503-
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are sorted in asc order.
1504+
* @hidden
1505+
* @internal
15041506
*/
15051507
@ContentChild(IgxSortAscendingHeaderIconDirective, { read: TemplateRef })
1506-
public sortAscendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1508+
public sortAscendingHeaderIconDirectiveTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
15071509

15081510
/**
1509-
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are sorted in desc order.
1511+
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are sorted in asc order.
1512+
*/
1513+
@Input()
1514+
public get sortAscendingHeaderIconTemplate(): TemplateRef<IgxGridHeaderTemplateContext> {
1515+
return this._sortAscendingHeaderIconTemplate;
1516+
}
1517+
1518+
/**
1519+
* Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in asc order.
1520+
*```html
1521+
* <ng-template #template igxSortAscendingHeaderIcon>
1522+
* <igx-icon>expand_less</igx-icon>
1523+
* </ng-template>
1524+
* ```
1525+
* ```typescript
1526+
* @ViewChild("'template'", {read: TemplateRef })
1527+
* public template: TemplateRef<any>;
1528+
* this.grid.sortAscendingHeaderIconTemplate = this.template;
1529+
* ```
15101530
*/
1531+
public set sortAscendingHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1532+
this._sortAscendingHeaderIconTemplate = template;
1533+
}
1534+
1535+
15111536
@ContentChild(IgxSortDescendingHeaderIconDirective, { read: TemplateRef })
1512-
public sortDescendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1537+
public sortDescendingHeaderIconDirectiveTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
15131538

15141539
/**
1515-
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are not sorted.
1540+
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are sorted in desc order.
1541+
*/
1542+
@Input()
1543+
public get sortDescendingHeaderIconTemplate() {
1544+
return this._sortDescendingHeaderIconTemplate;
1545+
}
1546+
1547+
/**
1548+
* Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in desc order.
1549+
*```html
1550+
* <ng-template #template igxSortDescendingHeaderIcon>
1551+
* <igx-icon>expand_more</igx-icon>
1552+
* </ng-template>
1553+
* ```
1554+
* ```typescript
1555+
* @ViewChild("'template'", {read: TemplateRef })
1556+
* public template: TemplateRef<any>;
1557+
* this.grid.sortDescendingHeaderIconTemplate = this.template;
1558+
* ```
1559+
*/
1560+
public set sortDescendingHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1561+
this._sortDescendingHeaderIconTemplate = template;
1562+
}
1563+
1564+
/**
1565+
* @hidden
1566+
* @internal
15161567
*/
15171568
@ContentChild(IgxSortHeaderIconDirective, { read: TemplateRef })
1518-
public sortHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1569+
public sortHeaderIconDirectiveTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1570+
1571+
/**
1572+
* Gets custom template, if any, that should be used when rendering a header sorting indicator when columns are not sorted.
1573+
*/
1574+
@Input()
1575+
public get sortHeaderIconTemplate(): TemplateRef<IgxGridHeaderTemplateContext> {
1576+
return this._sortHeaderIconTemplate;
1577+
}
1578+
1579+
/**
1580+
* Sets a custom template that should be used when rendering a header sorting indicator when columns are not sorted.
1581+
*```html
1582+
* <ng-template #template igxSortHeaderIcon>
1583+
* <igx-icon>unfold_more</igx-icon>
1584+
* </ng-template>
1585+
* ```
1586+
* ```typescript
1587+
* @ViewChild("'template'", {read: TemplateRef })
1588+
* public template: TemplateRef<any>;
1589+
* this.grid.sortHeaderIconTemplate = this.template;
1590+
* ```
1591+
*/
1592+
public set sortHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1593+
this._sortHeaderIconTemplate = template;
1594+
}
15191595

15201596
/**
15211597
* @hidden
@@ -3074,6 +3150,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
30743150
private readonly DRAG_SCROLL_DELTA = 10;
30753151
private _dataCloneStrategy: IDataCloneStrategy = new DefaultDataCloneStrategy();
30763152
private _autoSize = false;
3153+
private _sortHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
3154+
private _sortAscendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
3155+
private _sortDescendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
30773156

30783157
/**
30793158
* @hidden @internal
@@ -3647,6 +3726,18 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
36473726
* @hidden
36483727
*/
36493728
public ngAfterContentInit() {
3729+
if (this.sortHeaderIconDirectiveTemplate) {
3730+
this.sortHeaderIconTemplate = this.sortHeaderIconDirectiveTemplate;
3731+
}
3732+
3733+
if (this.sortAscendingHeaderIconDirectiveTemplate) {
3734+
this.sortAscendingHeaderIconTemplate = this.sortAscendingHeaderIconDirectiveTemplate;
3735+
}
3736+
3737+
if (this.sortDescendingHeaderIconDirectiveTemplate) {
3738+
this.sortDescendingHeaderIconTemplate = this.sortDescendingHeaderIconDirectiveTemplate;
3739+
}
3740+
36503741
this.setupColumns();
36513742
this.toolbar.changes.pipe(filter(() => !this._init), takeUntil(this.destroy$)).subscribe(() => this.notifyChanges(true));
36523743
this.setUpPaginator();

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,29 @@ describe('IgxGrid - Grid Sorting #grid', () => {
571571
expect(icon.nativeElement.textContent.toLowerCase().trim()).toBe('expand_more');
572572
});
573573

574+
it('Should allow setting custom templates for header sorting none/ascending/descending icons via Input.', () => {
575+
fixture = TestBed.createComponent(SortByParityComponent);
576+
fixture.detectChanges();
577+
grid = fixture.componentInstance.grid;
578+
grid.sortHeaderIconTemplate = fixture.componentInstance.sortIconTemplate;
579+
grid.sortAscendingHeaderIconTemplate = fixture.componentInstance.sortAscIconTemplate;
580+
grid.sortDescendingHeaderIconTemplate = fixture.componentInstance.sortDescIconTemplate;
581+
fixture.detectChanges();
582+
const header = GridFunctions.getColumnHeader('Name', fixture, grid);
583+
let icon = GridFunctions.getHeaderSortIcon(header);
584+
expect(icon.nativeElement.textContent.toLowerCase().trim()).toBe('arrow_right');
585+
586+
grid.sort({ fieldName: 'Name', dir: SortingDirection.Asc, ignoreCase: false });
587+
fixture.detectChanges();
588+
icon = GridFunctions.getHeaderSortIcon(header);
589+
expect(icon.nativeElement.textContent.toLowerCase().trim()).toBe('arrow_drop_up');
590+
591+
grid.sort({ fieldName: 'Name', dir: SortingDirection.Desc, ignoreCase: false });
592+
fixture.detectChanges();
593+
icon = GridFunctions.getHeaderSortIcon(header);
594+
expect(icon.nativeElement.textContent.toLowerCase().trim()).toBe('arrow_drop_down');
595+
});
596+
574597
it('Should be able to set single sorting mode and sort one column at a time', fakeAsync(() => {
575598
fixture = TestBed.createComponent(SortByParityComponent);
576599
fixture.detectChanges();

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from './grid-base-components.spec';
88
import { IGridSelection } from './grid-interfaces.spec';
99
import { SampleTestData, DataParent } from './sample-test-data.spec';
10-
import { ColumnDefinitions, GridTemplateStrings, EventSubscriptions, TemplateDefinitions } from './template-strings.spec';
10+
import { ColumnDefinitions, GridTemplateStrings, EventSubscriptions, TemplateDefinitions, ExternalTemplateDefinitions } from './template-strings.spec';
1111
import { IgxColumnComponent } from '../grids/columns/column.component';
1212
import { IgxFilteringOperand, IgxNumberFilteringOperand } from '../data-operations/filtering-condition';
1313
import { IFilteringExpressionsTree, FilteringExpressionsTree } from '../data-operations/filtering-expressions-tree';
@@ -2332,8 +2332,18 @@ export class NoColumnWidthGridComponent extends BasicGridComponent {
23322332
'',
23332333
'',
23342334
TemplateDefinitions.sortIconTemplates)
2335+
+ ExternalTemplateDefinitions.sortIconTemplates
23352336
})
23362337
export class SortByParityComponent extends GridDeclaredColumnsComponent implements ISortingStrategy {
2338+
@ViewChild('sortIcon', {read: TemplateRef })
2339+
public sortIconTemplate: TemplateRef<any>;
2340+
2341+
@ViewChild('sortAscIcon', {read: TemplateRef })
2342+
public sortAscIconTemplate: TemplateRef<any>;
2343+
2344+
@ViewChild('sortDescIcon', {read: TemplateRef })
2345+
public sortDescIconTemplate: TemplateRef<any>;
2346+
23372347
public sort(data: any[], fieldName: string, dir: SortingDirection) {
23382348
const key = fieldName;
23392349
const reverse = (dir === SortingDirection.Desc ? -1 : 1);

projects/igniteui-angular/src/lib/test-utils/template-strings.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,20 @@ export class TemplateDefinitions {
514514
`;
515515
}
516516

517+
export class ExternalTemplateDefinitions {
518+
public static sortIconTemplates = `
519+
<ng-template #sortIcon igxSortHeaderIcon>
520+
<igx-icon>arrow_right</igx-icon>
521+
</ng-template>
522+
<ng-template #sortAscIcon igxSortAscendingHeaderIcon>
523+
<igx-icon>arrow_drop_up</igx-icon>
524+
</ng-template>
525+
<ng-template #sortDescIcon igxSortDescendingHeaderIcon>
526+
<igx-icon>arrow_drop_down</igx-icon>
527+
</ng-template>
528+
`;
529+
}
530+
517531
export class EventSubscriptions {
518532

519533
public static columnInit = ` (columnInit)="columnInit($event)"`;

0 commit comments

Comments
 (0)