Articles in this section

How to Customize Save and Open Buttons in Bold Reports Report Designer

Published:
Updated:

To customize the Save and Open buttons in the Bold Reports .NET Core Report Designer, either hide the built-in buttons through toolbar settings and add your own buttons or override the built-in actions with the save-report-click and open-report-click events. Both approaches let you save and open reports from a custom location.

Steps

You can customize the buttons in two ways. Choose one.

Method 1: Hide the built-in buttons and add custom buttons

  1. Hide the Save and Open toolbar items. In .NET Core, set the toolbar items with a ViewBag value in the controller and remove Save and Open with a bitwise mask.

     public IActionResult Index()
    {
       ViewBag.toolbarSettings = new BoldReports.Models.ReportDesigner.ToolbarSettings();
       ViewBag.toolbarSettings.Items = BoldReports.ReportDesignerEnums.ToolbarItems.All
       & ~BoldReports.ReportDesignerEnums.ToolbarItems.Save
       & ~BoldReports.ReportDesignerEnums.ToolbarItems.Open;
       return View();
    }
    
  2. Bind the toolbar settings to the designer and add your own Open and Save buttons in the view.

    <button id="Open" type="button" value="Open">Open</button>
    <button id="Save" type="button" value="Save">Save</button>
    
    <div style="height: 600px; width: 100%;">
        <bold-report-designer id="reportdesigner1"
                              create="controlInitialized"
                              service-url="../Home"
                              report-data-extensions="@ViewBag.ReportDataExtensions"
                              toolbar-settings="@ViewBag.toolbarSettings"
                              ajax-before-load="ajaxBeforeLoad"
                              report-saved="reportSaved"
                              report-opened="reportOpened"
                              toolbar-click="toolbarClick"
                              report-modified="reportModified">
        </bold-report-designer>
    </div>
    
  3. Wire your buttons to the designer API so they open and save the report from your custom location. Each handler reads the designer instance before calling an API method, so the instance is always available.

    $("#Open").click(function (e) {
       var designer = $('#reportdesigner1').data('boldReportDesigner');
       // Set these from your own application. The server path format is "/<category>/<reportName>".
       var category = "Sample Reports";
       var reportName = "Sales Report";
       designer.openReport("/" + category + "/" + reportName);
    });
    
    $("#Save").click(function (e) {
       var designer = $('#reportdesigner1').data('boldReportDesigner');
       if (!designer.isNewServerReport()) {
           // Existing report: save it back to the same server path.
           designer.saveReport();
       } else {
           // New report: save it to a specific server path.
           // Path format is "/<category>/<reportName>"; isOverWrite = false creates a new report.
           designer.saveReport("/Sample Reports/Sales Report", false);
       }
    });
    

Method 2: Override the built-in button actions

  1. Keep the built-in buttons visible but handle their actions yourself. Bind the save-report-click and open-report-click events on the designer.

    <div style="height: 600px; width: 100%;">
        <bold-report-designer id="reportdesigner1"
                              create="controlInitialized"
                              service-url="../Home"
                              report-data-extensions="@ViewBag.ReportDataExtensions"
                              save-report-click="saveMenuClick"
                              open-report-click="openMenuClick"
                              ajax-before-load="ajaxBeforeLoad"
                              report-saved="reportSaved"
                              report-opened="reportOpened"
                              toolbar-click="toolbarClick"
                              report-modified="reportModified">
        </bold-report-designer>
    </div>
    
  2. In each handler, read the designer instance, check args.select to find which menu option was chosen, call the matching designer method, and set args.cancel = true to stop the default action. Every method below is part of the Report Designer JavaScript API.

    function openMenuClick(args) {
        var designer = $('#reportdesigner1').data('boldReportDesigner');
        switch (args.select) {
            case 'Device':
                // Open the report from the user's device.
                designer.openReportFromDevice();
                args.cancel = true;
                break;
            case 'Server':
                // Open the report from the report server.
                designer.openServerReportDialog();
                args.cancel = true;
                break;
        }
    }
    
    function saveMenuClick(args) {
        var designer = $('#reportdesigner1').data('boldReportDesigner');
        switch (args.select) {
            case 'Save':
                // Save the current report back to the server.
                designer.saveReport();
                args.cancel = true;
                break;
            case 'SaveAsDisk':
                // Download the report file to the device.
                designer.saveToDevice();
                args.cancel = true;
                break;
            case 'SaveAsServer':
                // Open the save-to-server dialog to choose a category and name.
                designer.saveServerReportDialog();
                args.cancel = true;
                break;
        }
    }
    

Result

With Method 1, the default Save and Open buttons no longer appear, and your custom buttons save and open reports from the location you specify. With Method 2, the built-in buttons stay in place but run your handlers instead of the default actions.

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied