JSReportViewerBase<T> Class
Base class for a client object that provides access to the client-side Document Viewer API.
Declaration
export class JSReportViewerBase<T extends DevExpress.Reporting.Viewer.Internal.PreviewDisposableModelBase = DevExpress.Reporting.Viewer.Internal.PreviewDisposableModelBase> extends BaseModel
Type Parameters
Name | Type |
---|---|
T | PreviewDisposableModelBase |
Remarks
To access the JSReportViewer object in applications based on different JS frameworks, use Knockout bindings as follows:
Angular | React | Vue |
---|---|---|
bindingSender property | the sender object in the event handler function used in callbacks binding | the sender object in the event handler function used in callbacks binding |
For code examples, review the class member descriptions.
Inheritance
constructor<T>(_previewModel)
Initializes a new instance of the JSReportViewerBase<T>
class with specified settings.
Declaration
constructor(
_previewModel: ko.Observable<T>
)
Parameters
Name | Type |
---|---|
_previewModel | Observable<T> |
Type Parameters
Name | Type |
---|---|
T | PreviewDisposableModelBase |
Properties
previewModel Property
Declaration
previewModel: T
Property Value
Type |
---|
T |
Methods
Close Method
Closes the document that is currently open in the Web Document Viewer.
Declaration
Close(): void
Remarks
The Close method closes the displayed document and leaves the Document Viewer empty. Call this method to release memory allocated on the server (storage and cache) when the user closes the page that contains the Document Viewer control.
The following code calls the Close method when a page (or UI region) window is about to close and unload its resources. The code uses jQuery API and handles the BeforeRender event.
function onBeforeRender(s, e) {
$(window).on('beforeunload', function(e) {
s.Close();
});
dispose Method
Declaration
dispose(): void
GetParametersModel Method
Allows you to access the report parameters client-side model.
Declaration
GetParametersModel(): DevExpress.Reporting.Viewer.Parameters.ParametersPanelModelBase
Returns
Type | Description |
---|---|
ParametersPanelModelBase | The report parameters client-side model. |
Remarks
The GetParametersModel method returns the parameter model that allows you to modify report parameters on the client before the user submits them.
Note
The parameter model is available only for visible parameters (parameters with the Visible property set to true).
Example - Obtain Parameter Values for a Multi-Value Parameter
The following code obtains values that the user selects in the multi-value parameter editor:
report-viewer.html
<div>
<dx-report-viewer [reportUrl]="reportUrl" height="800px">
<dxrv-request-options [invokeAction]="invokeAction" [host]="hostUrl">
</dxrv-request-options>
</dx-report-viewer>
</div>
report-viewer.ts
import { Component, Inject, ViewEncapsulation, ViewChild } from '@angular/core';
import { DxReportViewerComponent } from 'devexpress-reporting-angular';
@Component({
selector: 'report-viewer',
encapsulation: ViewEncapsulation.None,
templateUrl: './report-viewer.html',
styleUrls: [
// ...
]
})
export class ReportViewerComponent {
@ViewChild(DxReportViewerComponent, { static: false }) viewer: DxReportViewerComponent;
reportUrl: string = "XtraReport1";
invokeAction: string = '/DXXRDV';
GetClientParameter() {
var parametersModel = this.viewer.bindingSender.GetParametersModel();
var selectedValuesArray = parametersModel['MyMultiSelectParameterName'].value;
var firstValue = selectedValuesArray[0];
}
constructor(@Inject('BASE_URL') public hostUrl: string) { }
}
Example: Pass Parameter to the Report
The following code creates a button that passes a parameter to the report and rebuilds the document. When the document is created, the Document Viewer navigates to the last page:
report-viewer.html
<div>
<button (click)="BuildOnClick()"><span>Build Document</span></button>
</div>
<div>
<dx-report-viewer [reportUrl]="reportUrl" height="800px">
<dxrv-request-options [invokeAction]="invokeAction" [host]="hostUrl">
</dxrv-request-options>
<dxrv-callbacks (DocumentReady)="GoToLastPage($event)">
</dxrv-callbacks>
</dx-report-viewer>
</div>
report-viewer.ts
import { Component, Inject, ViewEncapsulation, ViewChild } from '@angular/core';
import { DxReportViewerComponent } from 'devexpress-reporting-angular';
@Component({
selector: 'report-viewer',
encapsulation: ViewEncapsulation.None,
templateUrl: './report-viewer.html',
styleUrls: [
// ...
]
})
export class ReportViewerComponent {
@ViewChild(DxReportViewerComponent, { static: false }) viewer: DxReportViewerComponent;
reportUrl: string = "XtraReport1";
invokeAction: string = '/DXXRDV';
BuildOnClick() {
var parameterValue = 1;
this.viewer.bindingSender.GetParametersModel()["parameter1"](parameterValue);
this.viewer.bindingSender.StartBuild();
}
GoToLastPage(event) {
this.viewer.bindingSender.GoToPage(event.args.PageCount - 1);
}
constructor(@Inject('BASE_URL') public hostUrl: string) { }
}
GetPreviewModel Method
Provides access to the Document Viewer’s client-side model.
Declaration
GetPreviewModel(): T
Returns
Type | Description |
---|---|
T | An object that is the client-side preview model. |
Remarks
Call the GetPreviewModel method to obtain the Document Viewer’s client-side model and adjust settings for the Document Viewer UI and the current document.
The following code snippet collapses the Parameters panel after the user resets parameter values.
<script type="text/javascript" id="script" >
function onParametersReset(s, e) {
var preview = s.GetPreviewModel();
if (preview) {
preview.tabPanel.collapsed = true;
}
}
</script>
@{
var viewerRender = Html.DevExpress().WebDocumentViewer("DocumentViewer")
.Height("1000px")
.ClientSideEvents(configure => configure.ParametersReset("onParametersReset"))
.Bind("TestReport");
@viewerRender.RenderHtml()
onPropertyChanged(args) Method
Declaration
onPropertyChanged(
args: DevExpress.Analytics.Serializer.Native.PropertyChangedEventArgs<any> | DevExpress.Analytics.Serializer.Native.ArrayPropertyChangedEventArgs<any>
): void
Parameters
Name | Type |
---|---|
args | PropertyChangedEventArgs<any> | ArrayPropertyChangedEventArgs<any> |
OpenReport(reportName) Method
Opens the specified report on the Web Document Viewer’s client side. Allows you to refresh preview for the loaded report.
Declaration
OpenReport(
reportName: any
): PromiseLike<DevExpress.Reporting.Viewer.Utils.IPreviewInitialize>
Parameters
Name | Type | Description |
---|---|---|
reportName | any | A string that specifies the report’s URL. |
Returns
Type |
---|
PromiseLike<IPreviewInitialize> |
Remarks
The client-side OpenReport method uses the report name resolution services to translate a report name to a report instance. For more information review the following help topic: Open a Report in ASP.NET Core Application.
Tip
You can call the OpenReport method with the current report name passed as the parameter to update the displayed report.
The following code creates a button that loads the “XtraReport1” report:
report-viewer.html
<div>
<button (click)="openReport()"><span>Open Report</span></button>
</div>
<div>
<dx-report-viewer [reportUrl]="reportUrl" height="800px">
<dxrv-request-options [invokeAction]="invokeAction" [host]="hostUrl"></dxrv-request-options>
</dx-report-viewer>
</div>
report-viewer.ts
import { Component, Inject, ViewEncapsulation, ViewChild } from '@angular/core';
import { DxReportViewerComponent } from 'devexpress-reporting-angular';
@Component({
selector: 'report-viewer',
encapsulation: ViewEncapsulation.None,
templateUrl: './report-viewer.html',
styleUrls: [
"../../../node_modules/devextreme/dist/css/dx.light.css",
"../../../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.common.css",
"../../../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.light.css",
"../../../node_modules/devexpress-reporting/dist/css/dx-webdocumentviewer.css"
]
})
export class ReportViewerComponent {
@ViewChild(DxReportViewerComponent, { static: false }) viewer: DxReportViewerComponent;
reportUrl: string = "TestReport";
invokeAction: string = '/DXXRDV';
openReport() {
var t = this.viewer.bindingSender.OpenReport("XtraReport1");
}
constructor(@Inject('BASE_URL') public hostUrl: string) { }
}
previewExists Method
Declaration
previewExists(): DevExpress.Reporting.Viewer.ReportHolder
Returns
Type |
---|
ReportHolder |
ResetParameters Method
Resets the report parameter values to the default values.
Declaration
ResetParameters(): void
Remarks
The method restores the default report parameter values and raises the ParametersReset event.
The following code creates a button that resets the report parameters. The ParametersReset event handler displays the parameter name and value.
report-viewer.html
<div>
<button (click)="btnOnClick()"><span>TEST</span></button>
</div>
<div>
<dx-report-viewer [reportUrl]="reportUrl" height="800px">
<dxrv-request-options [invokeAction]="invokeAction" [host]="hostUrl">
</dxrv-request-options>
<dxrv-callbacks (ParametersReset)="onParametersReset($event)">
</dxrv-callbacks>
</dx-report-viewer>
</div>
report-viewer.ts
import { Component, Inject, ViewEncapsulation, ViewChild } from '@angular/core';
import { DxReportViewerComponent } from 'devexpress-reporting-angular';
@Component({
selector: 'report-viewer',
encapsulation: ViewEncapsulation.None,
templateUrl: './report-viewer.html',
styleUrls: [
"../../../node_modules/devextreme/dist/css/dx.light.css",
"../../../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.common.css",
"../../../node_modules/@devexpress/analytics-core/dist/css/dx-analytics.light.css",
"../../../node_modules/devexpress-reporting/dist/css/dx-webdocumentviewer.css"
]
})
export class ReportViewerComponent {
@ViewChild(DxReportViewerComponent, { static: false }) viewer: DxReportViewerComponent;
reportUrl: string = "TestReport";
invokeAction: string = '/DXXRDV';
btnOnClick() {
this.viewer.bindingSender.ResetParameters();
}
onParametersReset(event) {
alert("Parameter " + event.args.Parameters[0].path + " is reset to " + event.args.Parameters[0].value);
}
constructor(@Inject('BASE_URL') public hostUrl: string) { }
}