Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ All notable changes for each version of this project will be documented in this
### New Features
- `Toolbar Actions`
- Exposed a new input property `overlaySettings` for all column actions (`hiding` | `pinning` | `advanced filtering` | `exporter`)
- `igxGrid`
- New `additionalTemplateContext` column input:

```html
<igx-column [additionalTemplateContext]="contextObject">
<ng-template igxCell let-cell="cell" let-props="additionalTemplateContext">
{{ props }}
</ng-template>
</igx-column>
```


## 12.0.3
Expand Down
3 changes: 2 additions & 1 deletion projects/igniteui-angular/src/lib/grids/cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
public get context(): any {
return {
$implicit: this.value,
cell: this
cell: this,
additionalTemplateContext: this.column.additionalTemplateContext
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,22 @@ export class IgxColumnComponent implements AfterContentInit, OnDestroy {
@Input()
public colStart: number;

/**
* Sets/gets custom properties provided in additional template context.
*
* ```html
* <igx-column [additionalTemplateContext]="contextObject">
* <ng-template igxCell let-cell="cell" let-props="additionalTemplateContext">
* {{ props }}
* </ng-template>
* </igx-column>
* ```
*
* @memberof IgxColumnComponent
*/
@Input()
public additionalTemplateContext: any;

/**
* @hidden
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ export interface ColumnType {
hasNestedPath: boolean;
defaultTimeFormat: string;
defaultDateTimeFormat: string;
additionalTemplateContext: any;
getGridTemplate(isRow: boolean, isIE: boolean): string;
}
40 changes: 40 additions & 0 deletions projects/igniteui-angular/src/lib/grids/grid/column.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('IgxGrid - Column properties #grid', () => {
ColumnsFromIterableComponent,
TemplatedColumnsComponent,
TemplatedInputColumnsComponent,
TemplatedContextInputColumnsComponent,
ColumnCellFormatterComponent,
ColumnHaederClassesComponent,
ColumnHiddenFromMarkupComponent,
Expand Down Expand Up @@ -308,6 +309,20 @@ describe('IgxGrid - Column properties #grid', () => {

});

it('should support passing properties through the templateContext input property', () => {
const fixture = TestBed.createComponent(TemplatedContextInputColumnsComponent);
fixture.detectChanges();

const grid = fixture.componentInstance.instance;
const contextObject = {property1: 'cellContent', property2: 'cellContent1'};
const firstColumn = grid.columns[0];
const secondColumn = grid.columns[1];

expect(firstColumn.additionalTemplateContext).toEqual(contextObject);
expect(firstColumn.cells[0].nativeElement.innerText).toEqual(contextObject.property1);
expect(secondColumn.cells[0].nativeElement.innerText).toEqual(contextObject.property2);
});

it('should apply column\'s formatter programmatically', () => {
const expectedVal = ['Johny', 'Sally', 'Tim'];
const expectedValToLower = ['johny', 'sally', 'tim'];
Expand Down Expand Up @@ -1133,6 +1148,31 @@ export class TemplatedInputColumnsComponent {
public columns = Object.keys(this.data[0]);
}


@Component({
template: `
<igx-grid [data]="data">
<igx-column [additionalTemplateContext]="contextObject" field="FirstName">
<ng-template igxCell let-cell="cell">
{{ cell.column.additionalTemplateContext.property1 }}
</ng-template>
</igx-column>
<igx-column [additionalTemplateContext]="contextObject" field="LastName">
<ng-template igxCell let-cell="cell" let-props="additionalTemplateContext">
{{ props.property2 }}
</ng-template>
</igx-column>
</igx-grid>
`
})
export class TemplatedContextInputColumnsComponent {
@ViewChild(IgxGridComponent, { read: IgxGridComponent, static: true })
public instance: IgxGridComponent;
public contextObject = {property1: 'cellContent', property2: 'cellContent1'};

public data = SampleTestData.personNameAgeData();
}

@Component({
template: `
<igx-grid [data]="data" height="500px" width="400px">
Expand Down