☝️Small business or a startup? See if you qualify for our special offer.
+
All documentation
  • Introduction
  • Connecting to data source
  • Browser compatibility
  • Documentation for older versions
  • Save and restore the report

    All your configurations for Flexmonster are contained in a report. In this guide, you can learn how each report and its configurations can be saved and restored in the component.

    In Flexmonster, you can also export, share, or print your report.

    Which configs are saved in the report

    The saved report can contain only configurations set in the ReportObject and GlobalObject, for example:

    • Mapping 
    • Expands and drill-downs
    • Sorting
    • Filters
    • Number and conditional formatting
    • Localization
    • Table sizes

    The configurations listed below are not saved:

    How to save the report

    Reports are saved in JSON format. You can save your report:

    • To the local file system
    • To a remote server
    • As a ReportObject

    To the local file system

    To save your report to the local file system, select the Save ( ) Toolbar tab or call the save() method with the destination: "file" parameter:

    const pivot = new Flexmonster({
    container: "pivotContainer",
    toolbar: true,
    report: {
    // Report configuration
    }
    });

    pivot.save({
    filename: "report.json",
    destination: "file"
    });

    Live example

    If you need to edit the report before saving it, we recommend getting the report as a ReportObject. Switch to the As a ReportObject tab to learn more.

    To a remote server

    To save your report to a remote server, call the save() method with the destination parameter set to "server" and the url parameter set to the server's address:

    const pivot = new Flexmonster({
    container: "pivotContainer",
    report: {
    // Report configuration
    }
    });

    pivot.save({
    filename: "report.json",
    destination: "server",
    url: "https://example.com/save-report",
    serverContentType: "application/json"
    });

    Notice serverContentType: "application/json" — we recommend adding this configuration since it allows saving large report files and simplifies parsing of the report on the server.

    When the save() method is called, Flexmonster creates an XMLHttpRequest object and sends it in a POST request to the server you specified in the url parameter. Your server must handle the request and save the report. Here is an example of getting the report on the server using Node.js and Express:

    server.post("/save-report", async (req, res) => {
    // You can save the report to the database, the server, etc.
    console.log("Flexmonster report:");
    console.log(req.body);
    res.json("Success!");
    });

    If you need to edit the report before saving it, we recommend getting the report as a ReportObject. Switch to the As a ReportObject tab to learn more.

    As a ReportObject

    When saving the report as a ReportObject, you can:

    • Add, replace, or remove some report configurations before saving the report.
    • Implement a custom approach to save the report to any location (e.g., the browser's local storage).

    To get the report as a ReportObject, use the getReport() method:

    const pivot = new Flexmonster({
    container: "pivotContainer",
    toolbar: true,
    report: {
    // Report configuration
    }
    });

    function customSaveFunction() {
    let report = pivot.getReport();
    // Parse, change, or save the report to a custom location
    }

    Live example

    Saving the report with the default and global configs

    By default, reports returned by the save() and getReport() methods contain only the configurations that were explicitly specified inside the ReportObject.

    For example, we have the component defined like this:

    const pivot = new Flexmonster({
    container: "pivot-container",
    global: {
    localization: "loc/es.json",
    options: {
    grid: {
    showHeaders: true
    },
    defaultHierarchySortName: "desc",
    readOnly: true
    }
    },
    report: {
    dataSource: {
    type: "csv",
    filename: "data/data-fr.csv"
    },
    options: {
    grid: {
    showGrandTotals: "rows"
    },
    readOnly: false
    },
    localization: "loc/fr.json",
    }
    });

    By default, save() and getReport() will return the following report:

    {
    "dataSource": {
    "type": "csv",
    "filename": "data/data-fr.csv"
    },
    "slice": {
    // Slice configs
    },
    "options": {
    "grid": {
    "showGrandTotals": "rows"
    }
    },
    "localization": "loc/fr.json"
    }

    The report is obtained with the configurations from the report object, but without configurations from the global object. Additionally, report.options.readOnly is not included, since its value matches the default one.

    To save the report with the default or global configs, you need to specify additional parameters:

    With defaults

    To save reports with default settings, use the withDefaults: true saving option:

    pivot.save({
    withDefaults: true
    });

    Note You can also use withDefaults for the getReport() API call.

    In the saved report, Flexmonster includes default values for configurations that are not defined in the ReportObject:

    {
    "dataSource": {
    "type": "csv",
    "browseForFile": false,
    "filename": "data/data-fr.csv",
    // Other dataSource properties with default values
    },
    "slice": {
    // Slice configs, including the ones with default values
    },
    "options": {
    "viewType": "grid",
    "grid": {
    "showGrandTotals": "rows",
    // Other grid options with default values
    },
    "chart": {
    // Chart options with default values
    },
    "filter": {
    // Filter options with default values
    },
    "readOnly": false,
    "configuratorActive": false,
    "configuratorButton": true,
    // Other options with default values
    }
    }

    Live example

    With globals

    To save reports with global settings, use the withGlobals: true saving option:

    pivot.save({
    withGlobals: true,
    });

    Note You can also use withGlobals for the getReport() API call.

    Check out the structure of the saved report:

    {
    "dataSource": {
    "type": "csv",
    "filename": "data/data-fr.csv"
    },
    "slice": {
    // Slice configs
    },
    "options": {
    "grid": {
    "showGrandTotals": "rows"
    },
    "defaultHierarchySortName": "desc"
    },
    "localization": "loc/fr.json"
    }

    The report configurations are saved based on the following principles:

    • If a configuration is set globally but not specified in the report, the global value will be included in the saved report (e.g., options.defaultHierarchySortName in the report above).
    • If a configuration exists both globally and in the report, the report-level value will be saved (e.g., localization in the report above).
    • If the report overrides a global configuration with a value that matches the configuration’s default value, this setting will not be included in the saved report (e.g., options.readOnly in the report above). 
    • If the global config matches the default value, it will not be saved (e.g., options.grid.showHeaders in the report above).

    Live example

    With defaults and globals

    To save reports with both default and global settings, use the withDefaults: true and withGlobals: true saving options:

    pivot.save({
    withGlobals: true,
    withDefaults: true
    });

    The saved report will look as follows:

    {
    "dataSource": {
    "type": "csv",
    "browseForFile": false,
    "filename": "data/data-fr.csv",
    // Other dataSource properties with default values
    },
    "slice": {
    // Slice configs, including the ones with default values
    },
    "options": {
    "viewType": "grid",
    "grid": {
    "showGrandTotals": "rows",
    "showHeaders": true,
    // Other grid options with default values
    },
    "chart": {
    // Chart options with default values
    },
    "filter": {
    // Filter options with default values
    },
    "defaultHierarchySortName": "desc",
    "readOnly": false,
    "configuratorActive": false,
    "configuratorButton": true,
    // Other options with their default values
    },
    "localization": "loc/fr.json"
    }

    In the saved report:

    • localization is defined in the report, so the global configuration is ignored.
    • options.readOnly is defined in both global and report configs, but the report-specific value is saved.
    • options.defaultHierarchySortName is only set globally, so it’s saved from the global config.
    • options.grid.showGrandTotals is defined only in the report and will be saved accordingly.
    • All other options are saved with their default values because withDefaults: true is used.

    Live example

    Using the saved report as a preset

    You can use the saved report file as a preset for Flexmonster so the component is loaded with a certain report configuration.

    To preset the report configuration, copy the content of the saved report file and paste it into the report property when initializing the component. Watch our video tutorial that gives a general overview of this approach:

    How to restore the report

    You can restore a report in the following ways:

    • From the local file system
    • From a remote server
    • From a ReportObject

    From the local file system

    To load a report from the local file system, select Open ( ) > Local report ( ) on the Toolbar or call the open() method:

    pivot.open();

    See an example with the open() method on JSFiddle.

    From a remote server

    To load a report from a remote server, select Open ( ) > Remote report ( ) on the Toolbar or call the load() method:

    pivot.load("https://example.com/get-report");

    See an example with the load() method on JSFiddle.

    Note The load() method can be used to load a report from a file on a server or from a server-side script that returns the report as a JSON object.

    From a ReportObject

    When restoring the report from a ReportObject, you can:

    • Add, replace, or remove some report configurations before restoring the report.
    • Implement a custom approach to load the report from any location (e.g., the browser's local storage).

    To set the report as a ReportObject, use the setReport() method:

    function customRestoreFunction() {
    // Get report from any location
    let report = {
    // Your report configuration
    };

    pivot.setReport(report);
    }

    Live example

    Examples

    1) Save the report with global and default configurations:

    pivot.save({
    withGlobals: true,
    withDefaults: true
    });

    Live example

    2) Save the initial report and restore it when needed:

    let report;

    const pivot = new Flexmonster({
    container: "pivotContainer",
    report: {
    // Report configuration
    },
    reportcomplete: () => {
    report = pivot.getReport();
    pivot.off("reportcomplete");
    }
    });

    function restoreInitialConfiguration() {
    pivot.setReport(report);
    }

    Live example

    3) Save the report to the local storage and restore it on a page refresh.

    This example shows how to save component configurations to the browser’s local storage and restore them on page reload.

    Other examples of saving and restoring the report can be found on the Examples page.

    What’s next?

    You may be interested in the following articles: