Skip to content

Commit aa16caa

Browse files
authored
Merge branch 'master' into mkirova/expose-excel-filtering-template
2 parents 6464b6e + 92bd943 commit aa16caa

File tree

5 files changed

+116
-28
lines changed

5 files changed

+116
-28
lines changed

CHANGELOG.md

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

1010
- `excelStyleHeaderIconTemplate` - Gets/Sets the excel style header icon.
1111
- `groupRowTemplate` - Gets/Sets the template reference for the group row.
12+
- `headSelectorTemplate` - Gets/Sets the header row selector template.
13+
- `rowSelectorTemplate` - Gets/Sets the custom template used for row selectors.
14+
- `groupByRowSelectorTemplate` - Gets/Sets the custom template used for the group row selectors.
1215
- `sortHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are not sorted.
1316
- `sortAscendingHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in asc order.
1417
- `sortDescendingHeaderIconTemplate` - Gets/Sets a custom template that should be used when rendering a header sorting indicator when columns are sorted in desc order.

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

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,15 +1210,15 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
12101210
* @hidden
12111211
* @internal
12121212
*/
1213-
@ContentChildren(IgxHeadSelectorDirective, { read: IgxHeadSelectorDirective, descendants: false })
1214-
public headSelectorsTemplates: QueryList<IgxHeadSelectorDirective>;
1213+
@ContentChildren(IgxHeadSelectorDirective, { read: TemplateRef, descendants: false })
1214+
public headSelectorsTemplates: QueryList<TemplateRef<IgxHeadSelectorTemplateContext>>;
12151215

12161216
/**
12171217
* @hidden
12181218
* @internal
12191219
*/
1220-
@ContentChildren(IgxRowSelectorDirective, { read: IgxRowSelectorDirective, descendants: false })
1221-
public rowSelectorsTemplates: QueryList<IgxRowSelectorDirective>;
1220+
@ContentChildren(IgxRowSelectorDirective, { read: TemplateRef, descendants: false })
1221+
public rowSelectorsTemplates: QueryList<TemplateRef<IgxRowSelectorTemplateContext>>;
12221222

12231223
/**
12241224
* @hidden
@@ -2505,15 +2505,28 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
25052505
}
25062506

25072507
/**
2508-
* @hidden
2509-
* @internal
2508+
* Gets the header row selector template.
25102509
*/
2510+
@Input()
25112511
public get headSelectorTemplate(): TemplateRef<IgxHeadSelectorTemplateContext> {
2512-
if (this.headSelectorsTemplates && this.headSelectorsTemplates.first) {
2513-
return this.headSelectorsTemplates.first.templateRef;
2514-
}
2512+
return this._headSelectorTemplate || this.headSelectorsTemplates.first;
2513+
}
25152514

2516-
return null;
2515+
/**
2516+
* Sets the header row selector template.
2517+
* ```html
2518+
* <ng-template #template igxHeadSelector let-headContext>
2519+
* {{ headContext.selectedCount }} / {{ headContext.totalCount }}
2520+
* </ng-template>
2521+
* ```
2522+
* ```typescript
2523+
* @ViewChild("'template'", {read: TemplateRef })
2524+
* public template: TemplateRef<any>;
2525+
* this.grid.headSelectorTemplate = this.template;
2526+
* ```
2527+
*/
2528+
public set headSelectorTemplate(template: TemplateRef<IgxHeadSelectorTemplateContext>) {
2529+
this._headSelectorTemplate = template;
25172530
}
25182531

25192532
/**
@@ -2532,18 +2545,30 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
25322545
return this.pinning.rows !== RowPinningPosition.Bottom;
25332546
}
25342547

2535-
/**
2536-
* @hidden
2537-
* @internal
2548+
/**
2549+
* Gets the row selector template.
25382550
*/
2551+
@Input()
25392552
public get rowSelectorTemplate(): TemplateRef<IgxRowSelectorTemplateContext> {
2540-
if (this.rowSelectorsTemplates && this.rowSelectorsTemplates.first) {
2541-
return this.rowSelectorsTemplates.first.templateRef;
2542-
}
2543-
2544-
return null;
2553+
return this._rowSelectorTemplate || this.rowSelectorsTemplates.first;
25452554
}
25462555

2556+
/**
2557+
* Sets a custom template for the row selectors.
2558+
* ```html
2559+
* <ng-template #template igxRowSelector let-rowContext>
2560+
* <igx-checkbox [checked]="rowContext.selected"></igx-checkbox>
2561+
* </ng-template>
2562+
* ```
2563+
* ```typescript
2564+
* @ViewChild("'template'", {read: TemplateRef })
2565+
* public template: TemplateRef<any>;
2566+
* this.grid.rowSelectorTemplate = this.template;
2567+
* ```
2568+
*/
2569+
public set rowSelectorTemplate(template: TemplateRef<IgxRowSelectorTemplateContext>) {
2570+
this._rowSelectorTemplate = template;
2571+
}
25472572

25482573
/**
25492574
* @hidden @internal
@@ -3070,10 +3095,13 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
30703095

30713096
private _customDragIndicatorIconTemplate: TemplateRef<IgxGridEmptyTemplateContext>;
30723097
private _excelStyleHeaderIconTemplate: TemplateRef<IgxGridHeaderTemplateContext>;
3098+
private _rowSelectorTemplate: TemplateRef<IgxRowSelectorTemplateContext>;
3099+
private _headSelectorTemplate: TemplateRef<IgxHeadSelectorTemplateContext>;
30733100
private _rowEditTextTemplate: TemplateRef<IgxGridRowEditTextTemplateContext>;
30743101
private _rowAddTextTemplate: TemplateRef<IgxGridEmptyTemplateContext>;
30753102
private _rowEditActionsTemplate: TemplateRef<IgxGridRowEditActionsTemplateContext>;
30763103
private _dragGhostCustomTemplate: TemplateRef<IgxGridRowDragGhostContext>;
3104+
30773105
private _cdrRequests = false;
30783106
private _resourceStrings;
30793107
private _emptyGridMessage = null;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,5 +2192,26 @@ describe('IgxGrid - Row Selection #grid', () => {
21922192
const firstRootRow = grid.gridAPI.get_row_by_index(0);
21932193
expect(firstRootRow.nativeElement.querySelector('.rowNumber').textContent).toEqual('15');
21942194
});
2195+
2196+
it('Should allow setting row, group row and header custom templates via Input.', () => {
2197+
grid.rowSelectorTemplate = fix.componentInstance.customRowTemplate;
2198+
grid.headSelectorTemplate = fix.componentInstance.customHeaderTemplate;
2199+
grid.groupByRowSelectorTemplate = fix.componentInstance.customGroupRowTemplate;
2200+
2201+
fix.detectChanges();
2202+
grid.groupBy({
2203+
fieldName: 'CompanyName', dir: SortingDirection.Desc, ignoreCase: false
2204+
});
2205+
fix.detectChanges();
2206+
const rowDOM = grid.dataRowList.toArray()[0].nativeElement;
2207+
const groupRowDOM = grid.groupsRowList.toArray()[0].nativeElement
2208+
const rowSelector = rowDOM.querySelector(`.igx-grid__cbx-selection`);
2209+
const groupRowSelector = groupRowDOM.querySelector(`.igx-grid__cbx-selection`);
2210+
const headerSelector = GridSelectionFunctions.getHeaderRow(fix).querySelector(`.igx-grid__cbx-selection`);
2211+
2212+
expect(rowSelector.textContent).toBe('CUSTOM SELECTOR: 0');
2213+
expect(groupRowSelector.textContent).toBe('CUSTOM GROUP SELECTOR');
2214+
expect(headerSelector.textContent).toBe('CUSTOM HEADER SELECTOR');
2215+
});
21952216
});
21962217
});

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
243243
* @hidden
244244
* @internal
245245
*/
246-
@ContentChildren(IgxGroupByRowSelectorDirective, { read: IgxGroupByRowSelectorDirective, descendants: false })
247-
protected groupByRowSelectorsTemplates: QueryList<IgxGroupByRowSelectorDirective>;
246+
@ContentChildren(IgxGroupByRowSelectorDirective, { read: TemplateRef, descendants: false })
247+
protected groupByRowSelectorsTemplates: QueryList<TemplateRef<IgxGroupByRowSelectorTemplateContext>>;
248248

249249
@ViewChildren(IgxGridGroupByRowComponent, { read: IgxGridGroupByRowComponent })
250250
private _groupsRowList: QueryList<IgxGridGroupByRowComponent>;
@@ -303,8 +303,11 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
303303
private _hideGroupedColumns = false;
304304
private _dropAreaMessage = null;
305305
private _showGroupArea = true;
306+
307+
private _groupByRowSelectorTemplate: TemplateRef<IgxGroupByRowSelectorTemplateContext>;
306308
private _detailTemplate;
307309

310+
308311
/**
309312
* Gets/Sets the array of data that populates the `IgxGridComponent`.
310313
*
@@ -567,14 +570,28 @@ export class IgxGridComponent extends IgxGridBaseDirective implements GridType,
567570
}
568571

569572
/**
570-
* @hidden
571-
* @internal
573+
* Gets the group by row selector template.
572574
*/
573-
public get groupByRowSelectorTemplate(): TemplateRef<IgxGroupByRowSelectorTemplateContext> {
574-
if (this.groupByRowSelectorsTemplates && this.groupByRowSelectorsTemplates.first) {
575-
return this.groupByRowSelectorsTemplates.first.templateRef;
576-
}
577-
return null;
575+
@Input()
576+
public get groupByRowSelectorTemplate(): TemplateRef <IgxGroupByRowSelectorTemplateContext> {
577+
return this._groupByRowSelectorTemplate || this.groupByRowSelectorsTemplates.first;
578+
}
579+
580+
/**
581+
* Sets the group by row selector template.
582+
* ```html
583+
* <ng-template #template igxGroupByRowSelector let-groupByRowContext>
584+
* {{ groupByRowContext.selectedCount }} / {{ groupByRowContext.totalCount }}
585+
* </ng-template>
586+
* ```
587+
* ```typescript
588+
* @ViewChild("'template'", {read: TemplateRef })
589+
* public template: TemplateRef<any>;
590+
* this.grid.groupByRowSelectorTemplate = this.template;
591+
* ```
592+
*/
593+
public set groupByRowSelectorTemplate(template: TemplateRef<IgxGroupByRowSelectorTemplateContext>) {
594+
this._groupByRowSelectorTemplate = template;
578595
}
579596

580597
/**

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1597,13 +1597,32 @@ export class DynamicColumnsComponent extends GridWithSizeComponent {
15971597
<igx-checkbox [checked]="headContext.totalCount === headContext.selectedCount"
15981598
(click)="onHeaderCheckboxClick($event, headContext)"></igx-checkbox>
15991599
</ng-template>
1600-
</igx-grid>`
1600+
</igx-grid>
1601+
<ng-template #customRow igxRowSelector let-rowContext>
1602+
<span class="rowNumber">CUSTOM SELECTOR: {{ rowContext.index }}</span>
1603+
</ng-template>
1604+
<ng-template #customHeader igxHeadSelector let-headContext>
1605+
<span>CUSTOM HEADER SELECTOR</span>
1606+
</ng-template>
1607+
<ng-template #customGroupRow igxGroupByRowSelector>
1608+
<span>CUSTOM GROUP SELECTOR</span>
1609+
</ng-template>
1610+
`
16011611
})
16021612
export class GridCustomSelectorsComponent extends BasicGridComponent implements OnInit {
16031613
@ViewChild('gridCustomSelectors', { static: true })
16041614
public grid: IgxGridComponent;
16051615
public rowCheckboxClick: any;
16061616
public headerCheckboxClick: any;
1617+
@ViewChild('customRow', {read: TemplateRef, static: true })
1618+
public customRowTemplate: TemplateRef<any>;
1619+
1620+
@ViewChild('customHeader', {read: TemplateRef, static: true })
1621+
public customHeaderTemplate: TemplateRef<any>;
1622+
1623+
@ViewChild('customGroupRow', {read: TemplateRef, static: true })
1624+
public customGroupRowTemplate: TemplateRef<any>;
1625+
16071626
public ngOnInit(): void {
16081627
this.data = SampleTestData.contactInfoDataFull();
16091628
}

0 commit comments

Comments
 (0)