☝️Small business or a startup? See if you qualify for our special offer.
+
All documentation
  • API Reference for older versions
  • save

    save(params: Object)

    Saves the current report to a specified location (e.g., to a server or to the local file system). The report is saved in JSON format.

    Parameters

    Parameter/TypeDescription
    params
    Object
    Contains parameters for saving the report.
    params.filename
    String
    A file name.
    params.destination
    String
    optional Defines where to save the generated file. The destination can be either "server" (the file will be saved to the server) or "file" (the file will be saved to the local file system). When saving to a server, Flexmonster creates an XMLHttpRequest and sends it as a POST request.
    Default value: "file".
    params.callbackHandler
    Function
    optional A JS function that is called when the report is saved. It has the following parameters:
    • resultResponseObject. Describes the result of saving. If saving fails, the result will be null.
    • errorResponseObject. Describes the error with saving. If saving is successful, the error will be null.
    params.url
    String
    optional A URL to the server-side script that saves the generated file. The file is sent as a POST parameter. Use this parameter only if the destination parameter is "server".
    params.embedData
    Boolean
    optional Specifies whether to save CSV data within the report or not.
    Default value: false.
    params.requestHeaders
    Object
    optional Adds custom request headers when saving the report to a server. This object consists of "key": "value" pairs, where "key" is a header’s name and "value" is its value.
    params.serverContentType
    String
    optional When saving the report to a server, this parameter allows you to set the Content‑Type header for the POST request:
    • "application/x‑www‑form‑urlencoded" — means that the report will be sent in an encoded string.
    • "application/json" — means that the report will be sent as a JSON string.
    Setting the serverContentType to "application/json" is recommended since it allows saving large report files and simplifies parsing of the report on the server.
    Use this parameter only if the destination parameter is "server".
    Default value: "application/x‑www‑form‑urlencoded".
    params.withDefaults
    Boolean
    optional Specifies whether the options with default values will be included in the report (true) or not (false).
    Learn more about saving the report with default values.
    Default value: false.
    params.withGlobals
    Boolean
    optional Specifies whether the global configs defined in the GlobalObject will be included in the report (true) or not (false).
    Learn more about saving the report with global configs.
    Default value: false.

    ResponseObject

    Property/TypeDescription
    report
    ReportObject
    optional The saved report. This property is available only when saving the report is successful.
    message
    String
    optional The error message. This property is available only when saving the report fails.
    response
    String
    optional The server’s response. This property is defined only when the destination parameter is set to "server".
    status
    Number
    optional The response status code. This property is defined only when the destination parameter is set to "server".

    Examples

    1) Saving a report to the local file system:

    pivot.save({ 
    filename: 'myreport.json',
    destination: 'file'
    });

    Live example

    2) Saving a report to the server:

    pivot.save({ 
    filename: 'myreport.json',
    destination: 'server',
    url: 'https://yourserver.com/yourscript.php'
    });

    Note The server-side script should be created on your back end to save reports to the server. And the url parameter is the path to this server-side script.

    3) Saving a report with default and global configurations:

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

    Live example

    4) Handling errors when saving to a server:

    pivot.save(
    {
    filename: 'report.json',
    destination: 'server',
    url: 'https://httpstat.us/404',
    serverContentType: 'application/json',
    callbackHandler: function(result, error) {
    if (error) {
    alert("response: " + error.response + "\nstatus: "
    + error.status + "\nmessage: "+ error.message);
    }
    }
    }
    );

    Live example

    See also