Skip to main content
All docs
V25.2
  • Customize the Report Viewer Toolbar

    • 3 minutes to read

    Use the following Report Viewer’s API to customize toolbar appearance:

    OnCustomizeToolbar
    Handle this event to add a new toolbar item or hide an existing item.
    ToolbarModel
    Use this property to obtain toolbar items.

    View Example: Report Viewer for Blazor - Customization Scenarios

    Add New Toolbar Item

    Add a Full Screen Button

    Handle the OnCustomizeToolbar event to add a custom command button to the toolbar. For example, this code adds a Full Screen button:

    Report Viewer for Blazor - Add Custom Command Buttons

    @page "/toolbar/"
    
    @using DevExpress.Blazor.Reporting
    @using DevExpress.XtraReports.UI
    @using BlazorCustomization.PredefinedReports
    @using DevExpress.Blazor.Reporting.Models
    
    @inject IJSRuntime JsRuntime
    
    
    <DxReportViewer @ref="reportViewer"
                    OnCustomizeToolbar="OnCustomizeToolbar"
                    Report="Report" />
    
    @code {
        DxReportViewer reportViewer;
        XtraReport Report = new TableReport();
    
        void OnCustomizeToolbar(ToolbarModel toolbarModel)
        {
            toolbarModel.AllItems.Add(new ToolbarItem()
            {
                // Use Open Iconic's icon.
                IconCssClass = "oi oi-command",
                Text = "Full Screen",
                AdaptiveText = "Full Screen",
                AdaptivePriority = 1,
                Click = async (args) =>
                {
                    await JsRuntime.InvokeVoidAsync("customApi.requestFullscreen", viewerComponent);
                }
            });
        }
    
    }
    

    Add a Send Email Button

    The following example handles the same CustomizeToolbar event to add a Send Email button. When a user clicks the button, a DxPopup window opens, and the user can specify export options:

    Blazor Report viewer - Custom Command Button

    View Example: Email a Report from the Native Blazor Report Viewer

    Hide Existing Toolbar Item

    The following code sample hides the Export To drop-down list in the toolbar:

    @using DevExpress.Blazor.Reporting.Models;
    // ...
    <DxReportViewer @ref="reportViewer"
                     OnCustomizeToolbar="OnCustomizeToolbar"/>
    
    @code {
        DxReportViewer reportViewer;
    
        void OnCustomizeToolbar(ToolbarModel toolbarModel)
        {
            foreach (var item in toolbarModel.AllItems)
            {
                if (item.Id == "ExportTo")
                {
                    item.GetEnabled = () => { return false; };
                    item.Visible = false;
                }
            }
        }
    }
    
    Built-In Toolbar
    Blazor Report Viewer -- Built-In Toolbar
    Customized Toolbar
    Blazor Report Viewer -- Customized Toolbar

    For the list of toolbar item identifiers, refer to the ToolbarItemId class.

    Hide Export Formats from ‘Export To’ Drop-Down List

    Use the Report Viewer’s ExportModel property to access document export settings and modify the Export To drop-down list.

    The following code sample hides all export formats except PDF and Image:

    @page "/hideexport/"
    
    @using DevExpress.Blazor.Reporting
    @using DevExpress.XtraReports.UI
    @using BlazorCustomization.PredefinedReports
    @using DevExpress.Blazor.Reporting.Models
    
    <div @ref="viewerComponent" style="width: 100%; height: 1000px;">
        <DxReportViewer @ref="reportViewer"
                        Report="Report" />
    </div>
    
    @code {
        DxReportViewer reportViewer;
        XtraReport Report = new TableReport();
        private ElementReference viewerComponent;
    
        var formats = new string[] { "Pdf", "Image" };
    
        protected override void OnAfterRender(bool firstRender) {
            if (firstRender) {
                reportViewer.ExportModel.AvailableFormats
                .RemoveAll(item => !formats.Contains(item.Name));
            }
        }    
    }
    

    The image below illustrates the customized toolbar.

    Report Viewer for Blazor -- Custom Toolbar Export Formats

    Change Zoom Level

    Use the Zoom property to set the zoom level of the document that the Report Viewer displays.

    The following code sets the zoom level to 125%:

    <DxReportViewer @ref="reportViewer"
                    Zoom="1.25"
                    Report="Report" />
    

    Use constants to set the zoom level to PageWidth and WholePage. The following snippet sets the zoom level to Page Width:

    @using DevExpress.Blazor.Reporting.Models
    @*...*@
    
    <DxReportViewer @ref="reportViewer" Report="Report" Zoom=ZoomConstants.PageWidth/>
    

    You can also use the UpdateZoomAsync method to change the page zoom level in the Report Viewer.

    Use the SinglePagePreview property to specify whether to display one or multiple pages in a preview.

    See Also