How to insert a button inside the ASP.NET MVC PivotGrid?
You can add a custom button to ASP.NET MVC PivotGrid using the DataBound event and edit pivot grid elements. Refer to the following code snippet for adding a custom button to pivot grid.
CSHTML
@Html.EJS().PivotView("PivotGrid").DataBound("onDataBound").Render()
Javascript
<script>
function onDataBound(args) {
//You can customize PivotGrid here
}
</script>
The following code snippet demonstrates how to insert a button inside the pivot grid.
Javascript
<script>
function onDataBound(args) {
//You can customize PivotGrid here
if (!document.getElementById("ExportIcon")) {
var pivotGridObj = document.getElementById("PivotGrid").ej2_instances[0];
var parent = document.createElement('div');
parent.setAttribute("id", "ExportIcon");
var child = document.createElement('div');
child.classList.add('e-icons');
child.classList.add('pivot-export');
parent.appendChild(child);
if (pivotGridObj.showFieldList) {
child.style.left = '38px';
document.getElementById("PivotGrid").insertBefore(parent, document.getElementById("PivotGrid").childNodes[1]);
} else {
document.getElementById("PivotGrid").insertBefore(parent, document.getElementById("PivotGrid").childNodes[0]);
}
document.getElementById('ExportIcon').onclick = function () {
pivotGridObj.pdfExport();
};
}
}
</script>
You can place a button or icon at the desired position in the pivot grid using CSS style.
CSS
<style>
.pivot-export::before {
content: '\e240';
}
.pivot-export {
top: 38px;
background-color: #fafafa;
border: 0.5px solid rgba(0, 0, 0, 0.12);
color: rgba(0, 0, 0, 0.54);
padding: 10px;
position: relative;
width: 38px;
z-index: 1000;
font-size: 20px;
height: 38px;
max-height: 38px;
max-width: 38px;
min-height: 38px;
min-width: 38px;
box-shadow: 1px 1px 4px 0 rgba(0, 0, 0, 0.12);
}
.e-toggle-field-list {
top: 38px;
}
</style>
The following screenshot illustrates the look of pivot grid after inserting a custom button.
Conclusion