mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
Support for column (cell) templates (#1513)
support for column (cell) templates readme updates and test fixes
This commit is contained in:
committed by
Eugenio Romano
parent
bf5482bf7b
commit
eacdfd7f6a
@@ -28,6 +28,12 @@
|
|||||||
key="name"
|
key="name"
|
||||||
sortable="true"
|
sortable="true"
|
||||||
class="full-width ellipsis-cell">
|
class="full-width ellipsis-cell">
|
||||||
|
<!-- Example of using custom column template -->
|
||||||
|
<!--
|
||||||
|
<template let-entry="$implicit">
|
||||||
|
<span>Hi! {{entry.data.getValue(entry.row, entry.col)}}</span>
|
||||||
|
</template>
|
||||||
|
-->
|
||||||
</content-column>
|
</content-column>
|
||||||
<content-column
|
<content-column
|
||||||
title="{{'DOCUMENT_LIST.COLUMNS.CREATED_BY' | translate}}"
|
title="{{'DOCUMENT_LIST.COLUMNS.CREATED_BY' | translate}}"
|
||||||
|
@@ -47,24 +47,28 @@
|
|||||||
(click)="onRowClick(row, $event)"
|
(click)="onRowClick(row, $event)"
|
||||||
(dblclick)="onRowDblClick(row, $event)"
|
(dblclick)="onRowDblClick(row, $event)"
|
||||||
[context-menu]="getContextMenuActions(row, col)">
|
[context-menu]="getContextMenuActions(row, col)">
|
||||||
<div *ngSwitchCase="'image'" class="cell-value">
|
<div *ngIf="!col.template">
|
||||||
<i *ngIf="isIconValue(row, col)" class="material-icons icon-cell">{{asIconValue(row, col)}}</i>
|
<div *ngSwitchCase="'image'" class="cell-value">
|
||||||
<img *ngIf="!isIconValue(row, col)"
|
<i *ngIf="isIconValue(row, col)" class="material-icons icon-cell">{{asIconValue(row, col)}}</i>
|
||||||
class="image-cell"
|
<img *ngIf="!isIconValue(row, col)"
|
||||||
alt="{{iconAltTextKey(data.getValue(row, col))|translate}}"
|
class="image-cell"
|
||||||
src="{{data.getValue(row, col)}}"
|
alt="{{iconAltTextKey(data.getValue(row, col))|translate}}"
|
||||||
(error)="onImageLoadingError($event)">
|
src="{{data.getValue(row, col)}}"
|
||||||
|
(error)="onImageLoadingError($event)">
|
||||||
|
</div>
|
||||||
|
<div *ngSwitchCase="'date'" class="cell-value" [attr.data-automation-id]="'date_' + data.getValue(row, col)">
|
||||||
|
{{data.getValue(row, col)}}
|
||||||
|
</div>
|
||||||
|
<div *ngSwitchCase="'text'" class="cell-value" [attr.data-automation-id]="'text_' + data.getValue(row, col)">
|
||||||
|
{{data.getValue(row, col)}}
|
||||||
|
</div>
|
||||||
|
<span *ngSwitchDefault class="cell-value">
|
||||||
|
<!-- empty cell for unknown column type -->
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchCase="'date'" class="cell-value" [attr.data-automation-id]="'date_' + data.getValue(row, col)">
|
<div *ngIf="col.template">
|
||||||
{{data.getValue(row, col)}}
|
<template ngFor [ngForOf]="[{ data: data, row: row, col: col }]" [ngForTemplate]="col.template"></template>
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchCase="'text'" class="cell-value" [attr.data-automation-id]="'text_' + data.getValue(row, col)">
|
|
||||||
{{data.getValue(row, col)}}
|
|
||||||
</div>
|
|
||||||
<span *ngSwitchDefault class="cell-value">
|
|
||||||
<!-- empty cell for unknown column type -->
|
|
||||||
</span>
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td *ngIf="actions">
|
<td *ngIf="actions">
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { TemplateRef } from '@angular/core';
|
||||||
|
|
||||||
export interface DataTableAdapter {
|
export interface DataTableAdapter {
|
||||||
selectedRow: DataRow;
|
selectedRow: DataRow;
|
||||||
getRows(): Array<DataRow>;
|
getRows(): Array<DataRow>;
|
||||||
@@ -41,6 +43,7 @@ export interface DataColumn {
|
|||||||
title?: string;
|
title?: string;
|
||||||
srTitle?: string;
|
srTitle?: string;
|
||||||
cssClass?: string;
|
cssClass?: string;
|
||||||
|
template?: TemplateRef<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DataSorting {
|
export class DataSorting {
|
||||||
|
@@ -414,7 +414,7 @@ the binding value for the Site column to display location site will be `location
|
|||||||
|
|
||||||
### Column definition
|
### Column definition
|
||||||
|
|
||||||
HTML attributes:
|
Properties:
|
||||||
|
|
||||||
| Name | Type | Default | Description
|
| Name | Type | Default | Description
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
@@ -425,10 +425,27 @@ HTML attributes:
|
|||||||
| `class` | string | | CSS class list, example: `full-width ellipsis-cell` |
|
| `class` | string | | CSS class list, example: `full-width ellipsis-cell` |
|
||||||
| `type` | string | text | Column type, text\|date\|number |
|
| `type` | string | text | Column type, text\|date\|number |
|
||||||
| `format` | string | | Value format pattern |
|
| `format` | string | | Value format pattern |
|
||||||
|
| `template` | `TemplateRef<any>` | | Column template |
|
||||||
|
|
||||||
For `date` column type the [DatePipe](https://angular.io/docs/ts/latest/api/common/DatePipe-class.html) formatting is used.
|
For `date` column type the [DatePipe](https://angular.io/docs/ts/latest/api/common/DatePipe-class.html) formatting is used.
|
||||||
For a full list of available `format` values please refer to [DatePipe](https://angular.io/docs/ts/latest/api/common/DatePipe-class.html) documentation.
|
For a full list of available `format` values please refer to [DatePipe](https://angular.io/docs/ts/latest/api/common/DatePipe-class.html) documentation.
|
||||||
|
|
||||||
|
#### Column Template
|
||||||
|
|
||||||
|
It is possible providing custom column/cell template that may contain other Angular components or HTML elmements:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<content-column
|
||||||
|
title="{{'DOCUMENT_LIST.COLUMNS.DISPLAY_NAME' | translate}}"
|
||||||
|
key="name"
|
||||||
|
sortable="true"
|
||||||
|
class="full-width ellipsis-cell">
|
||||||
|
<template let-entry="$implicit">
|
||||||
|
<span>Hi! {{entry.data.getValue(entry.row, entry.col)}}</span>
|
||||||
|
</template>
|
||||||
|
</content-column>
|
||||||
|
```
|
||||||
|
|
||||||
### Actions
|
### Actions
|
||||||
|
|
||||||
DocumentList supports declarative actions for Documents and Folders.
|
DocumentList supports declarative actions for Documents and Folders.
|
||||||
|
@@ -35,7 +35,7 @@ describe('ContentColumn', () => {
|
|||||||
spyOn(columnList, 'registerColumn').and.callThrough();
|
spyOn(columnList, 'registerColumn').and.callThrough();
|
||||||
|
|
||||||
let column = new ContentColumnComponent(columnList);
|
let column = new ContentColumnComponent(columnList);
|
||||||
column.ngOnInit();
|
column.ngAfterContentInit();
|
||||||
|
|
||||||
expect(columnList.registerColumn).toHaveBeenCalled();
|
expect(columnList.registerColumn).toHaveBeenCalled();
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ describe('ContentColumn', () => {
|
|||||||
let column = new ContentColumnComponent(columnList);
|
let column = new ContentColumnComponent(columnList);
|
||||||
spyOn(column, 'register').and.callThrough();
|
spyOn(column, 'register').and.callThrough();
|
||||||
|
|
||||||
column.ngOnInit();
|
column.ngAfterContentInit();
|
||||||
expect(column.register).toHaveBeenCalled();
|
expect(column.register).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnInit, Input } from '@angular/core';
|
import { Component, OnInit, Input, ContentChild, TemplateRef, AfterContentInit } from '@angular/core';
|
||||||
import { DataColumn } from 'ng2-alfresco-datatable';
|
import { DataColumn } from 'ng2-alfresco-datatable';
|
||||||
|
|
||||||
import { ContentColumnListComponent } from './content-column-list.component';
|
import { ContentColumnListComponent } from './content-column-list.component';
|
||||||
@@ -24,7 +24,7 @@ import { ContentColumnListComponent } from './content-column-list.component';
|
|||||||
selector: 'content-column',
|
selector: 'content-column',
|
||||||
template: ''
|
template: ''
|
||||||
})
|
})
|
||||||
export class ContentColumnComponent implements OnInit, DataColumn {
|
export class ContentColumnComponent implements OnInit, AfterContentInit, DataColumn {
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
key: string;
|
key: string;
|
||||||
@@ -41,6 +41,9 @@ export class ContentColumnComponent implements OnInit, DataColumn {
|
|||||||
@Input()
|
@Input()
|
||||||
title: string = '';
|
title: string = '';
|
||||||
|
|
||||||
|
@ContentChild(TemplateRef)
|
||||||
|
template: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title to be used for screen readers.
|
* Title to be used for screen readers.
|
||||||
*/
|
*/
|
||||||
@@ -56,7 +59,9 @@ export class ContentColumnComponent implements OnInit, DataColumn {
|
|||||||
if (!this.srTitle && this.key === '$thumbnail') {
|
if (!this.srTitle && this.key === '$thumbnail') {
|
||||||
this.srTitle = 'Thumbnail';
|
this.srTitle = 'Thumbnail';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngAfterContentInit() {
|
||||||
this.register();
|
this.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user