Skip to content

Commit 3e29d88

Browse files
authored
Merge branch 'master' into mkirova/expose-row-selector-template-inputs
2 parents e1c78a1 + 8d6f31c commit 3e29d88

File tree

5 files changed

+148
-7
lines changed

5 files changed

+148
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ All notable changes for each version of this project will be documented in this
1010
- `headSelectorTemplate` - Gets/Sets the header row selector template.
1111
- `rowSelectorTemplate` - Gets/Sets the custom template used for row selectors.
1212
- `groupByRowSelectorTemplate` - Gets/Sets the custom template used for the group row selectors.
13+
- `sortHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are not sorted.
14+
- `sortAscendingHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in asc order.
15+
- `sortDescendingHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in desc order.
1316
- `rowEditActionsTemplate` - Gets/Sets the row edit actions template.
1417
- `rowAddTextTemplate` - Gets/Sets the row add text template.
1518
- `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
@@ -1474,23 +1474,99 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
14741474
@ContentChild(IgxExcelStyleHeaderIconDirective, { read: TemplateRef })
14751475
public excelStyleHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
14761476

1477+
14771478
/**
1478-
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are sorted in asc order.
1479+
* @hidden
1480+
* @internal
14791481
*/
14801482
@ContentChild(IgxSortAscendingHeaderIconDirective, { read: TemplateRef })
1481-
public sortAscendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1483+
public sortAscendingHeaderIconDirectiveTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
14821484

14831485
/**
1484-
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are sorted in desc order.
1486+
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are sorted in asc order.
1487+
*/
1488+
@Input()
1489+
public get sortAscendingHeaderIconTemplate(): TemplateRef<IgxGridHeaderTemplateContext> {
1490+
return this._sortAscendingHeaderIconTemplate;
1491+
}
1492+
1493+
/**
1494+
* Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in asc order.
1495+
*```html
1496+
* <ng-template #template igxSortAscendingHeaderIcon>
1497+
* <igx-icon>expand_less</igx-icon>
1498+
* </ng-template>
1499+
* ```
1500+
* ```typescript
1501+
* @ViewChild("'template'", {read: TemplateRef })
1502+
* public template: TemplateRef<any>;
1503+
* this.grid.sortAscendingHeaderIconTemplate = this.template;
1504+
* ```
14851505
*/
1506+
public set sortAscendingHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1507+
this._sortAscendingHeaderIconTemplate = template;
1508+
}
1509+
1510+
14861511
@ContentChild(IgxSortDescendingHeaderIconDirective, { read: TemplateRef })
1487-
public sortDescendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1512+
public sortDescendingHeaderIconDirectiveTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
14881513

14891514
/**
1490-
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are not sorted.
1515+
* The custom template, if any, that should be used when rendering a header sorting indicator when columns are sorted in desc order.
1516+
*/
1517+
@Input()
1518+
public get sortDescendingHeaderIconTemplate() {
1519+
return this._sortDescendingHeaderIconTemplate;
1520+
}
1521+
1522+
/**
1523+
* Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in desc order.
1524+
*```html
1525+
* <ng-template #template igxSortDescendingHeaderIcon>
1526+
* <igx-icon>expand_more</igx-icon>
1527+
* </ng-template>
1528+
* ```
1529+
* ```typescript
1530+
* @ViewChild("'template'", {read: TemplateRef })
1531+
* public template: TemplateRef<any>;
1532+
* this.grid.sortDescendingHeaderIconTemplate = this.template;
1533+
* ```
1534+
*/
1535+
public set sortDescendingHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1536+
this._sortDescendingHeaderIconTemplate = template;
1537+
}
1538+
1539+
/**
1540+
* @hidden
1541+
* @internal
14911542
*/
14921543
@ContentChild(IgxSortHeaderIconDirective, { read: TemplateRef })
1493-
public sortHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1544+
public sortHeaderIconDirectiveTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
1545+
1546+
/**
1547+
* Gets custom template, if any, that should be used when rendering a header sorting indicator when columns are not sorted.
1548+
*/
1549+
@Input()
1550+
public get sortHeaderIconTemplate(): TemplateRef<IgxGridHeaderTemplateContext> {
1551+
return this._sortHeaderIconTemplate;
1552+
}
1553+
1554+
/**
1555+
* Sets a custom template that should be used when rendering a header sorting indicator when columns are not sorted.
1556+
*```html
1557+
* <ng-template #template igxSortHeaderIcon>
1558+
* <igx-icon>unfold_more</igx-icon>
1559+
* </ng-template>
1560+
* ```
1561+
* ```typescript
1562+
* @ViewChild("'template'", {read: TemplateRef })
1563+
* public template: TemplateRef<any>;
1564+
* this.grid.sortHeaderIconTemplate = this.template;
1565+
* ```
1566+
*/
1567+
public set sortHeaderIconTemplate(template: TemplateRef<IgxGridHeaderTemplateContext>) {
1568+
this._sortHeaderIconTemplate = template;
1569+
}
14941570

14951571
/**
14961572
* @hidden
@@ -3076,6 +3152,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
30763152
private readonly DRAG_SCROLL_DELTA = 10;
30773153
private _dataCloneStrategy: IDataCloneStrategy = new DefaultDataCloneStrategy();
30783154
private _autoSize = false;
3155+
private _sortHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
3156+
private _sortAscendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
3157+
private _sortDescendingHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext> = null;
30793158

30803159
/**
30813160
* @hidden @internal
@@ -3649,6 +3728,18 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
36493728
* @hidden
36503729
*/
36513730
public ngAfterContentInit() {
3731+
if (this.sortHeaderIconDirectiveTemplate) {
3732+
this.sortHeaderIconTemplate = this.sortHeaderIconDirectiveTemplate;
3733+
}
3734+
3735+
if (this.sortAscendingHeaderIconDirectiveTemplate) {
3736+
this.sortAscendingHeaderIconTemplate = this.sortAscendingHeaderIconDirectiveTemplate;
3737+
}
3738+
3739+
if (this.sortDescendingHeaderIconDirectiveTemplate) {
3740+
this.sortDescendingHeaderIconTemplate = this.sortDescendingHeaderIconDirectiveTemplate;
3741+
}
3742+
36523743
this.setupColumns();
36533744
this.toolbar.changes.pipe(filter(() => !this._init), takeUntil(this.destroy$)).subscribe(() => this.notifyChanges(true));
36543745
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';
@@ -2345,8 +2345,18 @@ export class NoColumnWidthGridComponent extends BasicGridComponent {
23452345
'',
23462346
'',
23472347
TemplateDefinitions.sortIconTemplates)
2348+
+ ExternalTemplateDefinitions.sortIconTemplates
23482349
})
23492350
export class SortByParityComponent extends GridDeclaredColumnsComponent implements ISortingStrategy {
2351+
@ViewChild('sortIcon', {read: TemplateRef })
2352+
public sortIconTemplate: TemplateRef<any>;
2353+
2354+
@ViewChild('sortAscIcon', {read: TemplateRef })
2355+
public sortAscIconTemplate: TemplateRef<any>;
2356+
2357+
@ViewChild('sortDescIcon', {read: TemplateRef })
2358+
public sortDescIconTemplate: TemplateRef<any>;
2359+
23502360
public sort(data: any[], fieldName: string, dir: SortingDirection) {
23512361
const key = fieldName;
23522362
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)