Articles in this section

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.

Pivot grid after inserting a custom button.


Conclusion

I hope you enjoyed learning on how to insert a button inside the ASP.NET MVC PivotGrid.
You can refer to our ASP.NET MVC PivotGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET MVC PivotGrid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!



Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied