Category / Section
How to Change the Export File Name with the Parameter Value
Published:
Updated:
To enhance the user experience and facilitate the identification and organization of exported reports, you can customize the export file name based on parameter values. By following the steps below, you will be able to provide more meaningful and dynamic names to your exported files:
- Register the
onRenderingComplete
andonExportItemClick
methods for renderingComplete and exportItemClick events, respectively. Here’s an example code sample for this:
$(function () {
var reportName = '';
$("#viewer").boldReportViewer({
reportServiceUrl: "https://demos.boldreports.com/services/api/ReportViewer",
reportPath: '~/Resources/docs/sales-order-detail.rdl',
renderingComplete: onRenderingComplete,
exportItemClick: onExportItemClick
});
});
- Add the following code sample to handle the renderingComplete event, which is triggered when the report rendering is complete:
function onRenderingComplete(event) {
var parameters = event.reportParameters;
if (parameters) {
for (var i = 0; i < parameters.length; i++) {
if (parameters[i].name == "SalesOrderNumber") {
reportName = parameters[i].values[0];
}
}
}
}
- Include the following code sample to handle the exportItemClick event, which is triggered when an export item is clicked:
function onExportItemClick(event) {
if(reportName != null && reportName != '' && reportName != undefined){
event.fileName = reportName;
}
}
- Run the application and change the parameter value. When you export the report, the exported file name will be dynamically set based on the parameter value.
You can download the sample application from here