Search results

Toolbar customization

You can hide the component toolbar to show customized user interface or to customize the toolbar icons and element’s appearances using the templates and Report Viewer toolbar customization properties.

In this tutorial, the sales-order-detail.rdl report is used and it can be downloaded from here. You can add the reports from the Syncfusion installation location. For more information, refer to Samples and demos.

Hide parameter block and toolbar items

To hide toolbar items, set the ToolbarSettings property. The following code can be used to remove the parameter option from the toolbar and hide the parameter block.

The following code example demonstrates how to hide the parameter block in the Report Viewer at client side.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/ReportViewer")
    .ReportPath("~/Resources/sales-order-detail.rdl")
    .ToolbarSettings(toolbar => toolbar.Items(BoldReports.ReportViewerEnums.ToolbarItems.All & ~BoldReports.ReportViewerEnums.ToolbarItems.Parameters))
)

Similarly, you can show or hide all other toolbar options with the help of ToolbarSettings.Items enum.

Hide toolbar

To hide the Report Viewer toolbar, set the ShowToolbar property to false.

The following code example demonstrates how to hide the toolbar in the Report Viewer at client side.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/ReportViewer")
    .ReportPath("~/Resources/sales-order-detail.rdl")
    .ToolbarSettings(toolbar => toolbar.ShowToolbar(false))
)

Decide or hide the export option

The Report Viewer provides the ExportOptions property to show or hide the default export types available in the component. The following code hides the HTML export type from the default export options.

The following code example demonstrates how to decide or hide the export option in the Report Viewer at client side.

@(Html.Bold().ReportViewer("viewer")
    .ReportServiceUrl("/api/ReportViewer")
    .ReportPath("~/Resources/sales-order-detail.rdl")
    .ExportSettings(export => export.ExportOptions(BoldReports.ReportViewerEnums.ExportOptions.All & ~BoldReports.ReportViewerEnums.ExportOptions.Html))
)

Add custom items to the export drop-down

To add custom items to the export drop-down available in the Report Viewer toolbar, use the property CustomItems and provide the JSON array of collection input with the Index, CssClass name, and Value properties. Register the ExportItemClick event to handle the custom item actions as given in following code snippet.

You can use the following codes to add custom items to the export drop-down from controller and passing the data to view using ViewBag.

    public ActionResult Index()
    {
        ExportSettings exportSettings = new ExportSettings();
        exportSettings.CustomItems = new List<CustomExportItem>();
        var exportItem1 = new CustomExportItem() { Index = 2, CssClass = "", Value = "Text File" };
        var exportItem2 = new CustomExportItem() { Index = 4, CssClass = "", Value = "DOT" };
        exportSettings.CustomItems.Add(exportItem1);
        exportSettings.CustomItems.Add(exportItem2);
        ViewBag.exportSettings = exportSettings;
        return View();
    }

You can use the following codes to set an ExportSettings property at client side.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ExportSettings(exportSettings => exportSettings.CustomItems(@ViewBag.exportSettings.CustomItems))
    )

You can use the following codes to create an ExportItemClick event at client side.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ExportItemClick("onExportItemClick")
    )

    <script type="text/javascript">
      function onExportItemClick(args) {
            alert('Action Triggered');
      }
    </script>

You can use the following codes to get ExportSettings properties on a dynamic object using ViewBag.exportSettings.CustomItems and invoke custom actions.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ExportSettings(exportSettings => exportSettings.CustomItems(@ViewBag.exportSettings.CustomItems)).ExportItemClick("onExportItemClick")
    )

    <script type="text/javascript">
        //Export click event handler
        function onExportItemClick(args) {
            if (args.value === "Text File") {
                //Implement the code to export report as Text
                alert("Text File export option clicked");
            } else if (args.value === "DOT") {
                //Implement the code to export report as DOT
                alert("DOT export option clicked");
            }
        }
    </script>

Add custom toolbar item

You can add custom items to Report Viewer toolbar using the ToolbarSettings property. You must register the ToolBarItemClick event to handle the newly added custom items action.

You can use the following codes to add custom toolbar item from controller and passing the data to view using ViewBag.

    public ActionResult Index()
    {
        ToolbarSettings toolbarSettings = new ToolbarSettings();
        toolbarSettings.CustomItems = new List<CustomItem>();

        var customItem = new CustomItem()
        {
            GroupIndex = 1,
            Index = 1,
            CssClass = "e-icon e-mail e-reportviewer-icon",
            Type = BoldReports.ReportViewerEnums.ToolBarItemType.Default,
            Id = "E-Mail",
            Tooltip = new ToolTip() { Header = "E-Mail", Content = "Send rendered report as mail attachment" }
        };

        toolbarSettings.CustomItems.Add(customItem);
        ViewBag.toolbarSettings = toolbarSettings;
        return View();
    }

You can use the following codes to set an ToolbarSettings property at client side.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ToolbarSettings(toolbarSettings => toolbarSettings.CustomItems(@ViewBag.toolbarSettings.CustomItems))
    )

You can use the following codes to create an ToolBarItemClick event at client side.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ToolBarItemClick("onToolBarItemClick")
    )

    <script type="text/javascript">
      function onToolBarItemClick(args) {
            alert('Action Triggered');
      }
    </script>

You can use the following codes to get ToolbarSettings properties on a dynamic object using ViewBag.toolbarSettings.CustomItems and invoke custom actions.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ToolbarSettings(toolbarSettings => toolbarSettings.CustomItems(@ViewBag.toolbarSettings.CustomItems))
        .ToolBarItemClick("onToolBarItemClick")
    )

    <script type="text/javascript">
      function onToolBarItemClick(args) {
            alert('Action Triggered');
        }
    </script>

Add custom item to exiting toolbar group

To add a custom item to existing toolbar group use the property CustomGroups in ToolbarSettings and provide the JSON array of collection input with the GroupIndex, Items, Type, CssClass Id, and Tooltip properties as given in following code snippet.

You can use the following codes to add custom item to exiting toolbar group from controller and passing the data to view using ViewBag.

    public ActionResult Index()
    {
        ToolbarSettings toolbarSettings = new ToolbarSettings();
        var groupItem = new List<CustomItem>();

        groupItem.Add(new CustomItem()
        {
            CssClass = "e-icon e-mail e-reportviewer-icon CustomGroup",
            Type = BoldReports.ReportViewerEnums.ToolBarItemType.Default,
            Id = "CustomGroup",
            Tooltip = new ToolTip() { Header = "CustomGroup", Content = "toolbargroups" }
        });

        groupItem.Add(new CustomItem()
        {
            CssClass = "e-icon e-mail e-reportviewer-icon subCustomGroup",
            Type = BoldReports.ReportViewerEnums.ToolBarItemType.Default,
            Id = "subCustomGroup",
            Tooltip = new ToolTip() { Header = "subCustomGroup", Content = "subtoolbargroups" }
        });

        toolbarSettings.CustomGroups.Add(new CustomGroup() { Items = groupItem, GroupIndex = 4 });
        ViewBag.toolbarSettings = toolbarSettings;
        return View();
    }

You can use the following codes to set an ToolbarSettings property at client side.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ToolbarSettings(toolbarSettings => toolbarSettings.CustomGroups(@ViewBag.toolbarSettings.CustomGroups))
    )

You can use the following codes to create an ToolBarItemClick event at client side.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ToolBarItemClick("onToolBarItemClick")
    )

    <script type="text/javascript">
      function onToolBarItemClick(args) {
            alert('Action Triggered');
      }
    </script>

You can use the following codes to get ToolbarSettings properties on a dynamic object using ViewBag.toolbarSettings.CustomGroups and invoke custom actions.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ToolbarSettings(toolbarSettings => toolbarSettings.CustomGroups(@ViewBag.toolbarSettings.CustomGroups))
        .ToolBarItemClick("onToolBarItemClick")
    )

    <script type="text/javascript">
        function onToolBarItemClick(args) {
            if (args.value === "CustomGroup") {
                //Implement the code to CustomGroup toolbar option
                alert("CustomGroup toolbar option clicked");
            }
            if (args.value === "subCustomGroup") {
                //Implement the code to subCustomGroup toolbar option
                alert("SubCustomGroup toolbar option clicked");
            }
        }
    </script>

Add new toolbar group

To add new toolbar group and custom items to it, use the property CustomItems in ToolbarSettings and provide the JSON array of collection input with the GroupIndex, Index properties. The CustomItem must have the properties Type, CssClass and Tooltip as given in following code snippet.

You can use the following codes to add new toolbar group from controller and passing the data to view using ViewBag.

    public ActionResult Index()
    {
        ToolbarSettings toolbarSettings = new ToolbarSettings();
        toolbarSettings.CustomItems = new List<CustomItem>();

        var customItem = new CustomItem()
        {
            GroupIndex = 1,
            Index = 1,
            CssClass = "e-icon e-mail e-reportviewer-icon",
            Type = BoldReports.ReportViewerEnums.ToolBarItemType.Default,
            Id = "E-Mail",
            Tooltip = new ToolTip() { Header = "E-Mail", Content = "Send rendered report as mail attachment" }
        };

        toolbarSettings.CustomItems.Add(customItem);
        ViewBag.toolbarSettings = toolbarSettings;
        return View();
    }

You can use the following codes to set an ToolbarSettings property at client side.

    @(Html.Bold().ReportViewer("viewer")
        .ReportServiceUrl("/api/ReportViewer")
        .ReportPath("~/Resources/sales-order-detail.rdl")
        .ToolbarSettings(toolbarSettings => toolbarSettings.CustomItems(@ViewBag.toolbarSettings.CustomItems))
    )