Provides property options to pass or set report parameters default values at run-time using the [parameters
] property. You can set the report parameters while creating the Report Viewer control in a script or in the Web API Controller.
In this tutorial, the
sales-order-dtail.rdl
report is used, and it can be downloaded from here.
namespace BlazorReportingTools.Data
{
public class BoldReportParameter
{
public string Name { get; set; }
public List <string> Values { get; set; }
public string popupWidth { get; set; }
public string popupHeight { get; set; }
public DateTime minDateTime { get; set; }
public DateTime maxDateTime { get; set; }
public string itemWidth { get; set; }
public string labelWidth { get; set; }
}
}
Set the default value data to the [values
] property and name of the report parameter to the [name
] property.
> The parameter name is case sensitive, it should be same as available in the report definition
sales-order-detail.rdl
report and the created BoldReportsAPI
URL in the Pages/Index.razor
file to visualize the report using our viewer.[Pages/Index.razor]
// index.razor file to pass a parameters
@code {
// ReportViewer options
BoldReportViewerOptions viewerOptions = new BoldReportViewerOptions();
// Used to render the Bold Report Viewer component in Blazor page.
public async void RenderReportViewer()
{
BoldReportParameter parameter = new BoldReportParameter();
viewerOptions.Parameters = new List<BoldReportParameter>();
parameter.Name = "SalesOrderNumber";
parameter.Values = new List<string>();
parameter.Values.Add("SO50753");
viewerOptions.Parameters.Add(parameter);
await JSRuntime.InvokeVoidAsync("BoldReports.RenderViewer", "report-viewer", viewerOptions);
}
}
boldreports-interop.js
file inside the wwwroot/scripts
folder and use the following code snippet to invoke the Bold Report Viewer JavaScript control.// Interop file to render the Bold Report Viewer component with properties.
window.BoldReports = {
RenderViewer: function (elementID, reportViewerOptions) {
$("#" + elementID).boldReportViewer
({
reportPath: reportViewerOptions.reportName,
reportServiceUrl: reportViewerOptions.serviceURL,
parameters: reportViewerOptions.parameters
});
}
}
To set parameter default value in Web API Controller, use the following code in the OnReportLoaded
method.
[NonAction]
public void OnReportLoaded(ReportViewerOptions reportOption)
{
List<BoldReports.Web.ReportParameter> userParameters = new List<BoldReports.Web.ReportParameter>();
userParameters.Add(new BoldReports.Web.ReportParameter()
{
Name = "SalesOrderNumber",
Values = new List<string>() { "SO50756" }
});
reportOption.ReportModel.Parameters = userParameters;
}
The Report Parameters name should be case sensitive
The ReportHelper
class provides methods that help you to get the report parameters used in the report. The following helper methods used to get parameter with or without values.
Methods | Description |
---|---|
GetParameters | Returns the parameters that are used in the current report without the processed values. |
GetParametersWithValues | Returns the report parameters with processed data values that are used in the current report. |
You can use the following code sample to get parameter names and set parameter default values. |
public class ReportsApiController : ApiController, IReportController
{
Dictionary<string, object> jsonArray = null;
public object PostReportAction(Dictionary<string, object> jsonResult)
{
jsonArray = jsonResult;
return ReportHelper.ProcessReport(jsonResult, this,_cache);
}
....
[NonAction]
public void OnReportLoaded(ReportViewerOptions reportOption)
{
var reportParameters = ReportHelper.GetParameters(jsonArray, this,_cache);
List<BoldReports.Web.ReportParameter> modifiedParameters = new List<BoldReports.Web.ReportParameter>();
if (reportParameters != null)
{
foreach (var rptParameter in reportParameters)
{
modifiedParameters.Add(new BoldReports.Web.ReportParameter()
{
Name = rptParameter.Name,
Values = new List<string>() { "SO50756" }
});
}
reportOption.ReportModel.Parameters = modifiedParameters;
}
}
}
Property | Description |
---|---|
minDateTime |
Specify minimum range value of a date parameter |
maxDateTime |
Specify maximum range value of a date parameter |
Refer to the following code sample to set date and time value to be display, using the Report Viewer component API’s.
*Create a Properties inside Data/BoldReportParameter.cs
class
// index.razor file to pass a parameters
public async void RenderReportViewer()
{
BoldReportParameter parameter = new BoldReportParameter();
viewerOptions.Parameters = new List<BoldReportParameter>();
parameter.minDateTime="3/1/2003";
parameter.maxDateTime="4/30/2003";
await JSRuntime.InvokeVoidAsync("BoldReports.RenderViewer", "report-viewer", viewerOptions);
}
// Interop file to render the Bold Report Viewer component with properties.
window.BoldReports = {
RenderViewer: function (elementID, reportViewerOptions) {
$("#" + elementID).boldReportViewer({
reportPath: reportViewerOptions.reportName,
reportServiceUrl: reportViewerOptions.serviceURL,
parameterSettings: {
minDateTime:reportViewerOptions.minDateTime,
maxDateTime:reportViewerOptions.maxDateTime,
}
});
}
}
The properties [dateTimeFormat
]and [timeDisplayFormat
]in the parameterSettings
are used to set date and time format to be displayed in the DateTimePicker control in a report.
Format | Display in DateTimePicker |
---|---|
Short Date and Time - d/M/yy h:mm tt |
9/12/2014 2:04 PM |
Medium Date - d MMM yy h:mm tt |
12 Sep 14 2:04: PM |
Full Date and short time - dddd, MMMM dd, yyyy HH:mm tt |
Friday, September 12,2014 2:04 PM |
Full Date and Long Time - dddd, MMMM dd, yyyy HH:mm:ss tt |
Friday, September 12,2014 2:04:00 PM |
UTC - yyyy-MM-dThh:mm:ssz |
2014-09-12T2:04:00+5 |
Refer to the following code sample to set date and time value to be display, using the Report Viewer component API’s.
<body style="overflow: hidden; position: static; margin: 0; padding: 0; height: 100%; width: 100%;">
<div id="viewer" style="position: absolute; height: 100%; width: 100%;"></div>
<script src="index.js"></script>
</body>
The above code sets date and time value to be display for all the date parameters used in the report.
To set different date and time value to be display for each date parameter used in the report, register the event beforeParameterAdd
and specify date and time value based on parameter name as in below code sample.
<body style="overflow: hidden; position: static; margin: 0; padding: 0; height: 100%; width: 100%;">
<div id="viewer" style="position: absolute; height: 100%; width: 100%;"></div>
<script src="beforeparameteradd.js"></script>
</body>
The parameterSettings
helps you to change the height and width of the parameter available in parameter panel.
// index.razor file to pass a parameters
public async void RenderReportViewer()
{
BoldReportParameter parameter = new BoldReportParameter();
viewerOptions.Parameters = new List<BoldReportParameter>();
parameter.popupHeight="150px";
parameter.popupWidth="250px";
await JSRuntime.InvokeVoidAsync("BoldReports.RenderViewer", "report-viewer", viewerOptions);
}
// Interop file to render the Bold Report Viewer component with properties.
window.BoldReports = {
RenderViewer: function (elementID, reportViewerOptions) {
$("#" + elementID).boldReportViewer({
reportPath: reportViewerOptions.reportName,
reportServiceUrl: reportViewerOptions.serviceURL,
parameterSettings: {
popupHeight: reportViewerOptions.popupHeight,
popupWidth: reportViewerOptions.popupWidth,
}
});
}
}
The enableparameterblockscroller
helps you to hide the scrollbar in parameter panel.
// Interop file to render the Bold Report Viewer component with properties.
window.BoldReports = {
RenderViewer: function (elementID, reportViewerOptions) {
$("#" + elementID).boldReportViewer({
enableParameterBlockScroller: false
});
}
}
The parameterSettings
helps you to hide and show the parameter block.
// Interop file to render the Bold Report Viewer component with properties.
window.BoldReports = {
RenderViewer: function (elementID, reportViewerOptions) {
$("#" + elementID).boldReportViewer({
parameterSettings: { hideParameterBlock: true}
});
}
}
The parameterSettings
helps you to change the parameter Item width and label width.
// index.razor file to pass a parameters
public async void RenderReportViewer()
{
BoldReportParameter parameter = new BoldReportParameter();
viewerOptions.Parameters = new List<BoldReportParameter>();
parameter.itemWidth="250px";
parameter.labelWidth="auto"
await JSRuntime.InvokeVoidAsync("BoldReports.RenderViewer", "report-viewer", viewerOptions);
}
// Interop file to render the Bold Report Viewer component with properties.
window.BoldReports = {
RenderViewer: function (elementID, reportViewerOptions) {
$("#" + elementID).boldReportViewer({
reportPath: reportViewerOptions.reportName,
reportServiceUrl: reportViewerOptions.serviceURL,
parameterSettings: parameterSettings: {
itemWidth: reportViewerOptions.itemWidth,
labelWidth: reportViewerOptions.labelWidth,
}
}
}
The accessInternalValue
property in the parameterSettings
helps you to expose the hidden
or internal
report parameter information used in report to the user.
// Interop file to render the Bold Report Viewer component with properties.
window.BoldReports = {
RenderViewer: function (elementID, reportViewerOptions) {
$("#" + elementID).boldReportViewer({
parameterSettings:{ accessInternalValue: true }
});
}
}
The Hidden
property of ReportParameter
allows you to show or hide the parameter at the top of the report viewer panel. The following code example shows hiding a report parameter in the Web API controller’s OnReportLoaded
method.
[NonAction]
public void OnReportLoaded(ReportViewerOptions reportOption)
{
var reportParameters = ReportHelper.GetParameters(jsonArray, this,_cache);
List<BoldReports.Web.ReportParameter> modifiedParameters = new List<BoldReports.Web.ReportParameter>();
if (reportParameters != null)
{
foreach (var rptParameter in reportParameters)
{
modifiedParameters.Add(new BoldReports.Web.ReportParameter()
{
Name = rptParameter.Name,
Hidden = true
});
}
reportOption.ReportModel.Parameters = modifiedParameters;
}
}