DevExtreme Angular - Client-Side Exporting and Printing

User Interaction

To export or print the widget, a user clicks Exporting/Printing and selects a command from the drop-down menu.

The Print command opens the browser's Print window. This window allows a user to specify the print settings and send the print job to the printer.

The other commands save a file in the selected format on the user's device.

Sankey Export Menu

Set export.enabled to true to enable exporting and printing. To allow a user to only export, assign false to export.printingEnabled.

jQuery
JavaScript
$(function() {
    $("#sankeyContainer").dxSankey({
        // ...
        export: {
            enabled: true,
            printingEnabled: false
        }
    });
});
Angular
HTML
TypeScript
<dx-sankey ... >
    <dxo-export
        [enabled]="true"
        [printingEnabled]="false">
    </dxo-export>
</dx-sankey>
import { DxSankeyModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxSankeyModule
    ],
    // ...
})

Change the export.formats array to limit the set of export formats. You can also set the fileName option to specify the export file's name.

jQuery
JavaScript
$(function() {
    $("#sankeyContainer").dxSankey({
        // ...
        export: {
            enabled: true,
            formats: ["PNG", "JPEG"],
            fileName: "exported_sankey"
        }
    });
});
Angular
HTML
TypeScript
<dx-sankey ... >
    <dxo-export
        [enabled]="true"
        [formats]="['PNG', 'JPEG']"
        fileName="exported_sankey">
    </dxo-export>
</dx-sankey>
import { DxSankeyModule } from "devextreme-angular";
// ...
export class AppComponent {
    // ...
}
@NgModule({
    imports: [
        // ...
        DxSankeyModule
    ],
    // ...
})

You should set up a server-side proxy to enable exporting and printing in Safari on MacOS.

API

To export the widget using the API, call the exportTo(fileName, format) method and pass the file name and format ("PNG", "PDF", "JPEG", "SVG" or "GIF") as the arguments. Call the print() method to print the widget. This command opens the browser's Print window.

jQuery
JavaScript
var sankey = $("#sankeyContainer").dxSankey("instance");
sankey.exportTo("exported_sankey", "PDF");
sankey.print();
Angular
TypeScript
import { ..., ViewChild } from "@angular/core";
import { DxSankeyModule, DxSankeyComponent } from "devextreme-angular";
// ...
export class AppComponent {
    @ViewChild(DxSankeyComponent) sankey: DxSankeyComponent;
    exportSankey() {
        this.sankey.instance.exportTo("exported_sankey", "PDF");
    };
    printSankey() {
        this.sankey.instance.print();
    };
}
@NgModule({
    imports: [
        // ...
        DxSankeyModule
    ],
    // ...
})

You can also export several widgets simultaneously using their SVG markup. Call the DevExpress.viz.getMarkup(widgetInstances) method to collect the markup from all the required widgets and pass it to the DevExpress.viz.exportFromMarkup(markup, options) method.

jQuery
JavaScript
var sankey1 = $("#sankeyContainer1").dxSankey("instance");
var sankey2 = $("#sankeyContainer2").dxSankey("instance");
var sankeyMarkup = DevExpress.viz.getMarkup([sankey1, sankey2]);

DevExpress.viz.exportFromMarkup(sankeyMarkup, {
    height: 768,
    width: 1024,
    fileName: "exported_sankeys",
    format: "PDF"
});
Angular
TypeScript
HTML
import { ..., ViewChild } from "@angular/core";
import { DxSankeyModule, DxSankeyComponent } from "devextreme-angular";
import exportMethods from "devextreme/viz/export";
// ...
export class AppComponent {
    @ViewChild("sankeyContainer1") sankey1: DxSankeyComponent;
    @ViewChild("sankeyContainer2") sankey2: DxSankeyComponent;
    exportSeveralSankeys() {
        let sankeyMarkup = exportMethods.getMarkup([this.sankey1.instance, this.sankey2.instance]);
        exportMethods.exportFromMarkup(sankeyMarkup, {
            height: 768,
            width: 1024,
            fileName: "exported_sankeys",
            format: "PDF"
        });
    };
}
@NgModule({
    imports: [
        // ...
        DxSankeyModule
    ],
    // ...
})
<dx-sankey id="sankeyContainer1" ... ></dx-sankey>
<dx-sankey id="sankeyContainer2" ... ></dx-sankey>

Events

DevExtreme data visualization widgets raise the following exporting-related events:

  • exporting
    Allows you to request export details or prevent exporting.

  • exported
    Allows you to notify an end user when exporting is completed.

  • fileSaving
    Allows you to access exported data in the BLOB format and/or prevent it from being saved on the user's device.

You can handle these events with functions. If the handling functions are not going to be changed at runtime, assign them to the onExporting, onExported and onFileSaving options when you configure the widget.

jQuery
JavaScript
$(function() {
    $("#sankeyContainer").dxSankey({
        // ...
        onExporting: function(e) {
            // Handler of the "exporting" event
        },
        onExported: function(e) {
            // Handler of the "exported" event
        },
        onFileSaving: function(e) {
            // Handler of the "fileSaving" event
        }
    });
});
Angular
HTML
TypeScript
<dx-sankey ...
    (onExporting)="onExporting($event)"
    (onExported)="onExported($event)"
    (onFileSaving)="onFileSaving($event)">
</dx-sankey>
import { DxSankeyModule } from "devextreme-angular";
// ...
export class AppComponent {
    onExporting(e) {
        // Handler of the "exporting" event
    };
    onExported(e) {
        // Handler of the "exported" event
    };
    onFileSaving(e) {
        // Handler of the "fileSaving" event
    }
}
@NgModule({
    imports: [
        // ...
        DxSankeyModule
    ],
    // ...
})

Otherwise (or if you need several handlers for a single event), subscribe to the exporting-related events using the on(eventName, eventHandler) method. This approach is more typical of jQuery.

JavaScript
var exportedHandler1 = function(e) {
    // First handler of the "exported" event
};

var exportedHandler2 = function(e) {
    // Second handler of the "exported" event
};

$("#sankeyContainer").dxSankey("instance")
    .on("exported", exportedHandler1)
    .on("exported", exportedHandler2);
See Also

Set Up a Server-Side Proxy

See the instructions here.