ReportDesignerPreviewClientSideEventsBuilder.OnExport(String) Method
Specifies the JavaScript function that handles the OnExport event, which occurs before a request for document export is sent.
Namespace: DevExpress.AspNetCore.Reporting.ReportDesigner
Assembly: DevExpress.AspNetCore.Reporting.v24.2.dll
NuGet Package: DevExpress.AspNetCore.Reporting
Declaration
Parameters
Name | Type | Description |
---|---|---|
callback | String | The name of a JavaScript function or entire JavaScript function code that runs when the OnExport event occurs. |
Returns
Type | Description |
---|---|
ReportDesignerPreviewClientSideEventsBuilder | A ReportDesignerPreviewClientSideEventsBuilder object instance that can be used for method chaining. |
Remarks
The OnExport
event occurs before the Report Designer Preview sends a request to print the document or to get the exported document.
Note
In v23.1 and higher, our Web Reporting Controls use the Fetch API for all request types. In earlier versions, the Web Reporting Controls used jQuery Ajax to send web requests, and form.submit
for export and print operations. The use of the Fetch API includes a unified method to pass request headers from a client to a back-end server. This eliminates the need to handle the OnExport
event to process custom request headers for export and print operations.
The handler function receives two parameters - the first parameter is the client-side Preview object, the second parameter is the object with the following properties:
- RequestUrl
- A string that specifies the request URL.
- FormData
- A set of key-value pairs.
Example
Tip
The following code snippets show how to pass the access token to the server if your application uses jQuery Ajax to send web requests, and form.submit
for export and print operations.
In v23.1 and higher, the Web Document Viewer uses the Fetch API to handle web requests, which includes a unified method to pass request headers from a client to a back-end server.
The following code handles the OnExport event on the client to pass the Bearer token to the server with a request for print or export if your application uses jQuery Ajax to handle requests (the ajaxSetup object):
<dx-report-designer [reportUrl]="reportUrl" height="800px">
<dxrd-callbacks (PreviewOnExport)="previewOnExport($event)">
</dxrd-callbacks>
<dxrd-request-options [getDesignerModelAction]="getDesignerModelAction" [host]="hostUrl"></dxrd-request-options>
</dx-report-designer>
The ConfigureJwtBearerOptions
service on the server parses the request and extracts the token:
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
namespace AspNetCore.Reporting.Common.Services {
public class ConfigureJwtBearerOptions : IPostConfigureOptions<JwtBearerOptions> {
public void PostConfigure(string name, JwtBearerOptions options) {
var originalOnMessageReceived = options.Events.OnMessageReceived;
options.Events.OnMessageReceived = async context => {
await originalOnMessageReceived(context);
if(string.IsNullOrEmpty(context.Token)
&& context.Request.HasFormContentType) {
var formData = await context.Request.ReadFormAsync();
var accessToken = formData?["access_token"];
var path = context.HttpContext.Request.Path;
if(!string.IsNullOrEmpty(accessToken) &&
path.StartsWithSegments("/DXXRDVAngular")) {
context.Token = accessToken;
}
}
};
}
}
}
Register the service at application startup:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Authentication.JwtBearer;
var builder = WebApplication.CreateBuilder(args);
builder.Services.TryAddEnumerable(
ServiceDescriptor.Singleton<IPostConfigureOptions<JwtBearerOptions>,
ConfigureJwtBearerOptions>());
var app = builder.Build();