Pricing changes are coming in January. Contact our Sales team to secure the current price for your desired license.
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 default name of the file.
    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 which 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.reportType
    String
    optional The report can be saved in "json" or "xml" format. Starting from version 2.6.0, the "xml" format is deprecated.
    Default value: "json".
    params.requestHeaders
    Object
    optional Allows you to add 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 Indicates whether the default values for options will be included in the report (true) or not (false).
    Default value: false.
    params.withGlobals
    Boolean
    optional Indicates whether the options defined in the GlobalObject will be included in the report (true) or not (false).
    Default value: false.

    ResponseObject

    Property/TypeDescription
    report
    ReportObject
    optional The saved report. This property is available only when saving the report was successful.
    message
    String
    optional The error message. This property is available only when saving the report failed.
    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) How to save a report to the local file system:

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

    Live example

    2) How to save 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) How to handle 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

    load
    getReport
    setReport
    shareReport
    Save and restore the report