Change the Parameters Programmatically in Native Blazor Report Viewer
Environment
Product | Progress® Telerik® Reporting |
Viwer | Native Blazor Report Viewer |
Description
I cannot get the Native Blazor Report Viewer to refresh the report based on new parameter values after displaying the report with default parameters. When I update parameters programmatically. For example, using a dropdown—the report does not refresh, even though the OnParametersSetAsync method executes with the new parameter values.
However, if I use the parameter input area in the Report Viewer interface, the report refreshes properly with the updated values. I need a way to programmatically pass new parameters and redisplay the report with these values.
This knowledge-base article also answers the following questions:
- How do I refresh the Native Blazor Report Viewer with new parameters?
- Why doesn't the Native Blazor Report Viewer reflect parameter changes programmatically?
- How can I pass changed parameters to Telerik Native Blazor Report Viewer?
Solution
To refresh the Native Blazor Report Viewer programmatically with new parameter values, ensure that you create a new ReportSourceOptions
object when updating the ReportSource
property. Modifying the existing object will not trigger the refresh. Below is an example demonstrating this approach.
Example
While the example below is made using the OnParametersSetAsync lifecycle event, it is not required to use this Blazor event, or any event at all, the
ReportSource
can be edited outside the Blazor events as well as long as a newReportSourceOptions
object is provided.
Use the following code snippet in the OnParametersSetAsync lifecycle event:
protected override async Task OnParametersSetAsync()
{
// Create a new ReportSourceOptions object with the updated parameters
var rso = new ReportSourceOptions()
{
Report = "Report1.trdp",
Parameters = new Dictionary<string, object>
{
{"Category", SelectedCategory} // Pass the updated parameter value
}
};
// Assign the new object to the ReportSource property
ReportSource = rso;
await base.OnParametersSetAsync();
}
Key Points
- Always create a new
ReportSourceOptions
object when updating theReportSource
property. - Assign the updated parameter values to the
Parameters
dictionary within the new object. - Ensure the
ReportSource
property references the new object to trigger the refresh.