mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1021] custom tooltip formatter for data columns (#2206)
* custom tooltip formatter for data columns * readme updates * unit tests
This commit is contained in:
committed by
Mario Romano
parent
09b213dd04
commit
fc46830f7d
@@ -102,9 +102,10 @@
|
|||||||
class="image-table-cell">
|
class="image-table-cell">
|
||||||
</data-column>
|
</data-column>
|
||||||
<data-column
|
<data-column
|
||||||
title="{{'DOCUMENT_LIST.COLUMNS.DISPLAY_NAME' | translate}}"
|
title="{{'DOCUMENT_LIST.COLUMNS.DISPLAY_NAME' | translate}}"
|
||||||
key="name"
|
key="name"
|
||||||
class="full-width ellipsis-cell">
|
[formatTooltip]="getNodeNameTooltip"
|
||||||
|
class="full-width ellipsis-cell">
|
||||||
</data-column>
|
</data-column>
|
||||||
<!-- Notes: has performance overhead due to multiple files/folders causing separate HTTP calls to get tags -->
|
<!-- Notes: has performance overhead due to multiple files/folders causing separate HTTP calls to get tags -->
|
||||||
<!--
|
<!--
|
||||||
|
@@ -24,6 +24,7 @@ import {
|
|||||||
DownloadZipDialogComponent, FileUploadCompleteEvent, FolderCreatedEvent, NotificationService,
|
DownloadZipDialogComponent, FileUploadCompleteEvent, FolderCreatedEvent, NotificationService,
|
||||||
SiteModel, UploadService
|
SiteModel, UploadService
|
||||||
} from 'ng2-alfresco-core';
|
} from 'ng2-alfresco-core';
|
||||||
|
import { DataColumn, DataRow } from 'ng2-alfresco-datatable';
|
||||||
import { DocumentListComponent, PermissionStyleModel } from 'ng2-alfresco-documentlist';
|
import { DocumentListComponent, PermissionStyleModel } from 'ng2-alfresco-documentlist';
|
||||||
|
|
||||||
import { ViewerService } from 'ng2-alfresco-viewer';
|
import { ViewerService } from 'ng2-alfresco-viewer';
|
||||||
@@ -283,4 +284,11 @@ export class FilesComponent implements OnInit {
|
|||||||
document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNodeNameTooltip(row: DataRow, col: DataColumn): string {
|
||||||
|
if (row) {
|
||||||
|
return row.getValue('name');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,9 @@ export class DataColumnComponent implements OnInit {
|
|||||||
@ContentChild(TemplateRef)
|
@ContentChild(TemplateRef)
|
||||||
template: any;
|
template: any;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
formatTooltip: Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title to be used for screen readers.
|
* Title to be used for screen readers.
|
||||||
*/
|
*/
|
||||||
@@ -57,5 +60,4 @@ export class DataColumnComponent implements OnInit {
|
|||||||
this.srTitle = 'Thumbnail';
|
this.srTitle = 'Thumbnail';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -178,6 +178,7 @@ Here's the list of available properties you can define for a Data Column definit
|
|||||||
| template | `TemplateRef` | | Custom column template |
|
| template | `TemplateRef` | | Custom column template |
|
||||||
| sr-title | string | | Screen reader title, used for accessibility purposes |
|
| sr-title | string | | Screen reader title, used for accessibility purposes |
|
||||||
| class | string | | Additional CSS class to be applied to column (header and cells) |
|
| class | string | | Additional CSS class to be applied to column (header and cells) |
|
||||||
|
| formatTooltip | Function | | Custom tooltip formatter function. |
|
||||||
|
|
||||||
### DataTable Events
|
### DataTable Events
|
||||||
|
|
||||||
@@ -233,6 +234,39 @@ The component will automatically check the corresponding i18n resources and fetc
|
|||||||
|
|
||||||
This feature is optional. Regular text either plain or converted via the `translate` pipe will still be working as it was before.
|
This feature is optional. Regular text either plain or converted via the `translate` pipe will still be working as it was before.
|
||||||
|
|
||||||
|
### Custom tooltips
|
||||||
|
|
||||||
|
You can create custom tooltips for the table cells by providing a `formatTooltip` property with a tooltip formatter function when declaring a data column.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<data-column
|
||||||
|
title="Name"
|
||||||
|
key="name"
|
||||||
|
[formatTooltip]="getNodeNameTooltip"
|
||||||
|
class="full-width ellipsis-cell">
|
||||||
|
</data-column>
|
||||||
|
```
|
||||||
|
|
||||||
|
And the code in this case will be similar to the following:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { DataColumn, DataRow } from 'ng2-alfresco-datatable';
|
||||||
|
|
||||||
|
@Component({...})
|
||||||
|
export class MyComponent {
|
||||||
|
...
|
||||||
|
|
||||||
|
getNodeNameTooltip(row: DataRow, col: DataColumn): string {
|
||||||
|
if (row) {
|
||||||
|
return row.getValue('name');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To disable the tooltip your function can return `null` or an empty string.
|
||||||
|
|
||||||
### Custom Empty content template
|
### Custom Empty content template
|
||||||
|
|
||||||
You can add a template that will be shown when there are no results in your datatable:
|
You can add a template that will be shown when there are no results in your datatable:
|
||||||
|
@@ -80,11 +80,13 @@
|
|||||||
(error)="onImageLoadingError($event)">
|
(error)="onImageLoadingError($event)">
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchCase="'date'" class="cell-value"
|
<div *ngSwitchCase="'date'" class="cell-value"
|
||||||
[attr.data-automation-id]="'date_' + data.getValue(row, col)">
|
[mdTooltip]="getCellTooltip(row, col)"
|
||||||
|
[attr.data-automation-id]="'date_' + data.getValue(row, col)">
|
||||||
<adf-datatable-cell [data]="data" [column]="col" [row]="row"></adf-datatable-cell>
|
<adf-datatable-cell [data]="data" [column]="col" [row]="row"></adf-datatable-cell>
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchCase="'text'" class="cell-value"
|
<div *ngSwitchCase="'text'" class="cell-value"
|
||||||
[attr.data-automation-id]="'text_' + data.getValue(row, col)">
|
[mdTooltip]="getCellTooltip(row, col)"
|
||||||
|
[attr.data-automation-id]="'text_' + data.getValue(row, col)">
|
||||||
<adf-datatable-cell [data]="data" [column]="col" [row]="row"></adf-datatable-cell>
|
<adf-datatable-cell [data]="data" [column]="col" [row]="row"></adf-datatable-cell>
|
||||||
</div>
|
</div>
|
||||||
<span *ngSwitchDefault class="cell-value">
|
<span *ngSwitchDefault class="cell-value">
|
||||||
|
@@ -586,4 +586,41 @@ describe('DataTable', () => {
|
|||||||
expect(event.target.src).toBe(originalSrc);
|
expect(event.target.src).toBe(originalSrc);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not get cell tooltip when row is not provided', () => {
|
||||||
|
const col = <DataColumn> { key: 'name', type: 'text' };
|
||||||
|
expect(dataTable.getCellTooltip(null, col)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not get cell tooltip when column is not provided', () => {
|
||||||
|
const row = <DataRow> {};
|
||||||
|
expect(dataTable.getCellTooltip(row, null)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not get cell tooltip when formatter is not provided', () => {
|
||||||
|
const col = <DataColumn> { key: 'name', type: 'text' };
|
||||||
|
const row = <DataRow> {};
|
||||||
|
expect(dataTable.getCellTooltip(row, col)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use formatter function to generate tooltip', () => {
|
||||||
|
const tooltip = 'tooltip value';
|
||||||
|
const col = <DataColumn> {
|
||||||
|
key: 'name',
|
||||||
|
type: 'text',
|
||||||
|
formatTooltip: () => tooltip
|
||||||
|
};
|
||||||
|
const row = <DataRow> {};
|
||||||
|
expect(dataTable.getCellTooltip(row, col)).toBe(tooltip);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return null value from the tooltip formatter', () => {
|
||||||
|
const col = <DataColumn> {
|
||||||
|
key: 'name',
|
||||||
|
type: 'text',
|
||||||
|
formatTooltip: () => null
|
||||||
|
};
|
||||||
|
const row = <DataRow> {};
|
||||||
|
expect(dataTable.getCellTooltip(row, col)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -412,6 +412,16 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCellTooltip(row: DataRow, col: DataColumn): string {
|
||||||
|
if (row && col && col.formatTooltip) {
|
||||||
|
const result: string = col.formatTooltip(row, col);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private emitRowSelectionEvent(name: string, row: DataRow) {
|
private emitRowSelectionEvent(name: string, row: DataRow) {
|
||||||
const domEvent = new CustomEvent(name, {
|
const domEvent = new CustomEvent(name, {
|
||||||
detail: {
|
detail: {
|
||||||
|
@@ -47,6 +47,7 @@ export interface DataColumn {
|
|||||||
srTitle?: string;
|
srTitle?: string;
|
||||||
cssClass?: string;
|
cssClass?: string;
|
||||||
template?: TemplateRef<any>;
|
template?: TemplateRef<any>;
|
||||||
|
formatTooltip?: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DataSorting {
|
export class DataSorting {
|
||||||
|
@@ -16,14 +16,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { MdButtonModule, MdCheckboxModule, MdIconModule, MdMenuModule } from '@angular/material';
|
import {
|
||||||
|
MdButtonModule,
|
||||||
|
MdCheckboxModule,
|
||||||
|
MdIconModule,
|
||||||
|
MdMenuModule,
|
||||||
|
MdTooltipModule
|
||||||
|
} from '@angular/material';
|
||||||
|
|
||||||
export function modules() {
|
export function modules() {
|
||||||
return [
|
return [
|
||||||
MdCheckboxModule,
|
MdCheckboxModule,
|
||||||
MdMenuModule,
|
MdMenuModule,
|
||||||
MdIconModule,
|
MdIconModule,
|
||||||
MdButtonModule
|
MdButtonModule,
|
||||||
|
MdTooltipModule
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -309,7 +309,7 @@ Note the `#documentList` ID we've just added to be able referencing this compone
|
|||||||
import { ViewChild, AfterViewInit } from '@angular/core';
|
import { ViewChild, AfterViewInit } from '@angular/core';
|
||||||
import { DocumentListComponent } from 'ng2-alfresco-documentlist';
|
import { DocumentListComponent } from 'ng2-alfresco-documentlist';
|
||||||
|
|
||||||
@Component(...)
|
@Component({...})
|
||||||
export class MyAppComponent implements AfterViewInit {
|
export class MyAppComponent implements AfterViewInit {
|
||||||
|
|
||||||
myStartFolder: string = '-my-';
|
myStartFolder: string = '-my-';
|
||||||
@@ -366,7 +366,7 @@ DocumentList provides simple breadcrumb element to indicate the current position
|
|||||||
|
|
||||||
| Name | Returned Type | Description |
|
| Name | Returned Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| navigate | [PathElementEntity](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/PathElementEntity.md) |emitted when user clicks on a breadcrumb |
|
| navigate | [PathElementEntity](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/PathElementEntity.md) | emitted when user clicks on a breadcrumb |
|
||||||
|
|
||||||
## Dropdown Site Component
|
## Dropdown Site Component
|
||||||
|
|
||||||
@@ -410,29 +410,29 @@ A custom set of columns can look like the following:
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<adf-document-list ...>
|
<adf-document-list ...>
|
||||||
<content-columns>
|
<data-columns>
|
||||||
<content-column key="$thumbnail" type="image"></content-column>
|
<data-column key="$thumbnail" type="image"></data-column>
|
||||||
<content-column
|
<data-column
|
||||||
title="Name"
|
title="Name"
|
||||||
key="name"
|
key="name"
|
||||||
sortable="true"
|
sortable="true"
|
||||||
class="full-width ellipsis-cell">
|
class="full-width ellipsis-cell">
|
||||||
</content-column>
|
</data-column>
|
||||||
<content-column
|
<data-column
|
||||||
title="Created By"
|
title="Created By"
|
||||||
key="createdByUser.displayName"
|
key="createdByUser.displayName"
|
||||||
sortable="true"
|
sortable="true"
|
||||||
class="desktop-only">
|
class="desktop-only">
|
||||||
</content-column>
|
</data-column>
|
||||||
<content-column
|
<data-column
|
||||||
title="Created On"
|
title="Created On"
|
||||||
key="createdAt"
|
key="createdAt"
|
||||||
type="date"
|
type="date"
|
||||||
format="medium"
|
format="medium"
|
||||||
sortable="true"
|
sortable="true"
|
||||||
class="desktop-only">
|
class="desktop-only">
|
||||||
</content-column>
|
</data-column>
|
||||||
</content-columns>
|
</data-columns>
|
||||||
</adf-document-list>
|
</adf-document-list>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -466,6 +466,7 @@ Here's the list of available properties you can define for a Data Column definit
|
|||||||
| template | `TemplateRef` | | Custom column template |
|
| template | `TemplateRef` | | Custom column template |
|
||||||
| sr-title | string | | Screen reader title, used for accessibility purposes |
|
| sr-title | string | | Screen reader title, used for accessibility purposes |
|
||||||
| class | string | | Additional CSS class to be applied to column (header and cells) |
|
| class | string | | Additional CSS class to be applied to column (header and cells) |
|
||||||
|
| formatTooltip | Function | | Custom tooltip formatter function. |
|
||||||
|
|
||||||
DocumentList component assigns an instance of `MinimalNode` type (`alfresco-js-api`) as a data context of each row.
|
DocumentList component assigns an instance of `MinimalNode` type (`alfresco-js-api`) as a data context of each row.
|
||||||
|
|
||||||
@@ -499,14 +500,14 @@ Here's a short example:
|
|||||||
|
|
||||||
```html
|
```html
|
||||||
<adf-document-list ...>
|
<adf-document-list ...>
|
||||||
<content-columns>
|
<data-columns>
|
||||||
<content-column key="$thumbnail" type="image"></content-column>
|
<data-column key="$thumbnail" type="image"></data-column>
|
||||||
<content-column title="Name" key="name" class="full-width ellipsis-cell"></content-column>
|
<data-column title="Name" key="name" class="full-width ellipsis-cell"></data-column>
|
||||||
<content-column
|
<data-column
|
||||||
title="Created By"
|
title="Created By"
|
||||||
key="createdByUser.displayName">
|
key="createdByUser.displayName">
|
||||||
</content-column>
|
</data-column>
|
||||||
</content-columns>
|
</data-columns>
|
||||||
</adf-document-list>
|
</adf-document-list>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -544,9 +545,9 @@ You can use all three properties to gain full access to underlying data from wit
|
|||||||
In order to wire HTML templates with the data context you will need defining a variable that is bound to `$implicit` like shown below:
|
In order to wire HTML templates with the data context you will need defining a variable that is bound to `$implicit` like shown below:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<template let-context="$implicit">
|
<ng-template let-context="$implicit">
|
||||||
<!-- template body -->
|
<!-- template body -->
|
||||||
</template>
|
</ng-template>
|
||||||
```
|
```
|
||||||
|
|
||||||
The format of naming is `let-VARIABLE_NAME="$implicit"` where `VARIABLE_NAME` is the name of the variable you want to bind template data context to.
|
The format of naming is `let-VARIABLE_NAME="$implicit"` where `VARIABLE_NAME` is the name of the variable you want to bind template data context to.
|
||||||
@@ -567,12 +568,12 @@ context.row.getValue('createdByUser.displayName')
|
|||||||
You may want using **row** api to get raw value access.
|
You may want using **row** api to get raw value access.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<content-column title="Name" key="name" sortable="true" class="full-width ellipsis-cell">
|
<data-column title="Name" key="name" sortable="true" class="full-width ellipsis-cell">
|
||||||
<template let-context="$implicit">
|
<ng-template let-context="$implicit">
|
||||||
<span>Hi! {{context.row.getValue('createdByUser.displayName')}}</span>
|
<span>Hi! {{context.row.getValue('createdByUser.displayName')}}</span>
|
||||||
<span>Hi! {{context.row.getValue('name')}}</span>
|
<span>Hi! {{context.row.getValue('name')}}</span>
|
||||||
</template>
|
</ng-template>
|
||||||
</content-column>
|
</data-column>
|
||||||
```
|
```
|
||||||
|
|
||||||
Use **data** api to get values with post-processing, like datetime/icon conversion._
|
Use **data** api to get values with post-processing, like datetime/icon conversion._
|
||||||
@@ -580,25 +581,25 @@ Use **data** api to get values with post-processing, like datetime/icon conversi
|
|||||||
In the Example below we will prepend `Hi!` to each file and folder name in the list:
|
In the Example below we will prepend `Hi!` to each file and folder name in the list:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<content-column title="Name" key="name" sortable="true" class="full-width ellipsis-cell">
|
<data-column title="Name" key="name" sortable="true" class="full-width ellipsis-cell">
|
||||||
<template let-entry="$implicit">
|
<ng-template let-entry="$implicit">
|
||||||
<span>Hi! {{entry.data.getValue(entry.row, entry.col)}}</span>
|
<span>Hi! {{entry.data.getValue(entry.row, entry.col)}}</span>
|
||||||
</template>
|
</ng-template>
|
||||||
</content-column>
|
</data-column>
|
||||||
```
|
```
|
||||||
|
|
||||||
In the Example below we will add the [ng2-alfresco-tag](https://www.npmjs.com/package/ng2-alfresco-tag) component is integrate in the document list.
|
In the Example below we will add the [ng2-alfresco-tag](https://www.npmjs.com/package/ng2-alfresco-tag) component is integrate in the document list.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<content-column
|
<data-column
|
||||||
title="{{'DOCUMENT_LIST.COLUMNS.TAG' | translate}}"
|
title="{{'DOCUMENT_LIST.COLUMNS.TAG' | translate}}"
|
||||||
key="id"
|
key="id"
|
||||||
sortable="true"
|
sortable="true"
|
||||||
class="full-width ellipsis-cell">
|
class="full-width ellipsis-cell">
|
||||||
<template let-entry="$implicit">
|
<ng-template let-entry="$implicit">
|
||||||
<adf-tag-node-list [nodeId]="entry.data.getValue(entry.row, entry.col)"></adf-tag-node-list>
|
<adf-tag-node-list [nodeId]="entry.data.getValue(entry.row, entry.col)"></adf-tag-node-list>
|
||||||
</template>
|
</ng-template>
|
||||||
</content-column>
|
</data-column>
|
||||||
```
|
```
|
||||||
|
|
||||||

|

|
||||||
@@ -938,6 +939,39 @@ DocumentList emits the following events:
|
|||||||
|
|
||||||
## Advanced usage and customization
|
## Advanced usage and customization
|
||||||
|
|
||||||
|
### Custom tooltips
|
||||||
|
|
||||||
|
You can create custom tooltips for the table cells by providing a `formatTooltip` property with a tooltip formatter function when declaring a data column.
|
||||||
|
|
||||||
|
```html
|
||||||
|
<data-column
|
||||||
|
title="Name"
|
||||||
|
key="name"
|
||||||
|
[formatTooltip]="getNodeNameTooltip"
|
||||||
|
class="full-width ellipsis-cell">
|
||||||
|
</data-column>
|
||||||
|
```
|
||||||
|
|
||||||
|
And the code in this case will be similar to the following:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { DataColumn, DataRow } from 'ng2-alfresco-datatable';
|
||||||
|
|
||||||
|
@Component({...})
|
||||||
|
export class MyComponent {
|
||||||
|
...
|
||||||
|
|
||||||
|
getNodeNameTooltip(row: DataRow, col: DataColumn): string {
|
||||||
|
if (row) {
|
||||||
|
return row.getValue('name');
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To disable the tooltip your function can return `null` or an empty string.
|
||||||
|
|
||||||
### Custom row filter
|
### Custom row filter
|
||||||
|
|
||||||
You can create a custom row filter implementation that returns `true` if row should be displayed or `false` to hide it.
|
You can create a custom row filter implementation that returns `true` if row should be displayed or `false` to hide it.
|
||||||
|
Reference in New Issue
Block a user