Having trouble getting help?
Contact Support
Contact Support
Show tooltip for row and column headers
8 Aug 20238 minutes to read
You can create and display the tooltip for each row and column header(s) in the pivot table by using an external tooltip component via the dataBound event.
import { PivotView, IDataSet, IAxisSet } from '@syncfusion/ej2-pivotview';
import { pivotData } from './datasource.ts';
import { Tooltip } from '@syncfusion/ej2-popups';
let headerTooltip: Tooltip;
let pivotTableObj: PivotView = new PivotView({
dataSourceSettings: {
dataSource: pivotData as IDataSet[],
expandAll: false,
enableSorting: true,
columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }],
rows: [{ name: 'Country' }, { name: 'Products' }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
filters: []
},
dataBound: (): void => {
if (!headerTooltip) {
headerTooltip = new Tooltip({
target: 'td.e-rowsheader,th.e-columnsheader', beforeRender: beforeRender
});
headerTooltip.appendTo(pivotTableObj.element);
}
},
height: 350
});
pivotTableObj.appendTo('#PivotTable');
// Method used to customize the tooltip content while hovering each row and column headers in the pivot table.
function beforeRender(args: any) {
if (args.target.parentElement.querySelector('.e-rowsheader')) {
// Here you can set custom content for row header(s) tooltip from its cell information.
let index: number = Number(args.target.getAttributeNode('index').value);
let colIndex: number = Number(args.target.getAttributeNode('data-colindex').value);
let cell: IAxisSet = pivotTableObj.engineModule.pivotValues[index][colIndex];
let valueText: any = cell.valueSort ? cell.valueSort : '';
if (cell.formattedText !== 'Grand Total') {
this.content =
'<div>' +
'FieldName: ' +
valueText.axis +
'</br>' +
'Text: ' +
cell.formattedText +
'</div>';
} else {
this.content =
'<div>' +
'FieldName: ' +
valueText.uniqueName +
'</br>' +
'Text: ' +
cell.formattedText +
'</div>';
}
} else {
// Here you can set custom content for column header(s) tooltip from its cell information.
if (args.target.querySelector('.e-cellvalue')) {
this.content = args.target.querySelector('.e-cellvalue').innerText;
} else if (args.target.querySelector('.e-headertext')) {
this.content = args.target.querySelector('.e-headertext').innerText;
} else if (args.target.querySelector('.e-stackedheadercelldiv')) {
this.content = args.target.querySelector('.e-stackedheadercelldiv').innerText;
} else {
this.content = '';
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Pivot Grid</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Pivot Grid Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-calendars/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-grids/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-charts/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-pivotview/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div>
<div id='PivotTable'></div>
</div>
</div>
</body>
</html>