Articles in this section

How to Auto-Refresh Bold Reports Viewer on Parameter Change

Published:
Updated:

To auto-refresh the Bold Reports JavaScript Report Viewer when parameter values change, implement a polling timer or parameter change listener function that monitors the parameter input element and triggers a click on the View Report button or calls the viewer refresh method without manual user interaction.

When to use this

Use this when you want reports to regenerate immediately upon selecting or changing a parameter value (such as dates, categories, or IDs), eliminating the requirement for users to manually locate and click the View Report button on the toolbar.

Step 1: Set up the HTML and Required Dependencies

Include the Bold Reports styles, scripts, and required dependencies (jQuery). Note that CodeMirror is only needed if you are embedding an SQL query editor or expression editor; it is not required for standard Report Viewer rendering.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Auto-Refresh Bold Reports JavaScript Report Viewer</title>
    <!-- Report Viewer component styles -->
	<link href="https://cdn.boldreports.com/15.1.10/content/v2.0/tailwind-light/bold.report-viewer.min.css" rel="stylesheet" />
	<!-- Report Viewer component dependent script -->
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
	<script src="https://cdn.boldreports.com/15.1.10/scripts/v2.0/common/bold.reports.common.min.js"></script>
	<script src="https://cdn.boldreports.com/15.1.10/scripts/v2.0/common/bold.reports.widgets.min.js"></script>
	<!-- Report Viewer component script -->
	<script src="https://cdn.boldreports.com/15.1.10/scripts/v2.0/bold.report-viewer.min.js"></script>
</head>
<body style="overflow: hidden; position: static; margin: 0; padding: 0; height: 100%; width: 100%;">
    <!-- Viewer container -->
    <div id="viewer" style="position: absolute; height: 100%; width: 100%;"></div>
</body>
</html>

Step 2: Initialize the Report Viewer and Add the Auto-Refresh Polling Function

Add the script to initialize the Bold Report Viewer and configure an interval-based polling function using setTimeout to detect changes on the target parameter DOM element:

<script type="text/javascript">
    $(function () {
        // Initialize Bold Reports Report Viewer
        var reportViewer = $("#viewer").boldReportViewer({
            reportServiceUrl: "https://demos.boldreports.com/services/api/ReportViewerWebApi",
            reportPath: 'sales-order-detail.rdl'
        }).data("boldReportViewer");
        // Function to monitor parameter changes and trigger refresh
        // Auto-refresh function
           function checkParameterChange() {
               var currentValue = $("#viewer_Param_101").val(); // replace with your real generated id
               if (currentValue !== checkParameterChange.lastValue) {
                   $("#viewer_viewReportClick").click();
                   checkParameterChange.lastValue = currentValue;
               }
               setTimeout(checkParameterChange, 1000); // Schedule next check
           }
        // Start parameter monitoring
        checkParameterChange();
    });
</script>

Performance Note: Set the polling interval based on user experience needs. An interval between 1000ms (1 second) and 1500ms offers responsive updates while preventing excessive CPU usage or server query overhead.

Step 3: Identify the Parameter and View Report Elements

The Report Viewer generates parameter controls dynamically. The generated IDs may vary depending on the viewer instance and report parameter configuration.

To locate the correct element IDs:

  1. Open the application in a browser.
  2. Press F12 to open Developer Tools.
  3. Inspect the parameter control rendered by the viewer.
  4. Note the generated parameter element ID.
  5. Locate the View Report button element and note its ID.

Important: viewer_Param_101 and viewer_viewReportClick are example IDs only. Verify the generated IDs in your application before implementing the script.

Step 4: Run and Verify the Application

  1. Run your web application in a browser.
  2. Select a different value from the parameter dropdown or enter a new value into the parameter text box.
  3. The report automatically re-renders with fresh data without requiring a click on the View Report button.

Result

Modifying any monitored parameter value automatically submits the updated parameters and triggers the report generation cycle. The toolbar’s View Report button click action executes programmatically behind the scenes.

Related articles

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