[ADF-1021] custom tooltip formatter for data columns (#2206)

* custom tooltip formatter for data columns

* readme updates

* unit tests
This commit is contained in:
Denys Vuika
2017-08-14 11:26:36 +01:00
committed by Mario Romano
parent 09b213dd04
commit fc46830f7d
10 changed files with 175 additions and 39 deletions

View File

@@ -80,11 +80,13 @@
(error)="onImageLoadingError($event)">
</div>
<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>
</div>
<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>
</div>
<span *ngSwitchDefault class="cell-value">

View File

@@ -586,4 +586,41 @@ describe('DataTable', () => {
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();
});
});

View File

@@ -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) {
const domEvent = new CustomEvent(name, {
detail: {