Get Free Trial
API reference
Table of contents

save

save(params: Object)

[starting from version: 2.302]

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

params – Object. It can have the following properties:

  • filename – String. A default name of the file.
  • destination optional – String. 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".
  • callbackHandler optional – Function. A JS function that is called when the report is saved. It has the following parameters:
    • result – Object. Describes the result of saving. If saving fails, the result will be null. The result object can have the following properties:
      • reportReportObject. The saved report.
      • response optional – String. The server’s response. This property is defined in the result only when the destination is set to "server".
      • status optional – Number. The response status code. This property is defined in the result only when the destination is set to "server".
    • error – Object. Describes the error with saving. If saving is successful, the error will be null. The error object can have the following properties:
      • message – String. The error message.
      • response optional – String. The server’s response. This property is defined in the error only when the destination is set to "server".
      • status optional – Number. The response status code. This property is defined in the error only when the destination is set to "server".
  • url optional – String. 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".
  • embedData optional – Boolean. Specifies whether to save CSV data within the report or not. Default value: false.
  • reportType optional – String. The report can be saved in "json" or "xml" format. Starting from version 2.6.0, the "xml" format is deprecated. Default value: "json".
  • requestHeaders optional – Object. 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.
  • withDefaults optional – Boolean. Indicates whether the default values for options will be included in the report (true) or not (false). Default value: false.
  • withGlobals optional – Boolean. Indicates whether the options defined in the GlobalObject will be included in the report (true) or not (false). Default value: false.

Examples

1) How to save a report to the local file system:

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

Check out on JSFiddle.

2) How to save a report to the server:

flexmonster.save({ 
filename: 'myreport.json',
destination: 'server',
url: 'http://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:

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

See the live sample on JSFiddle.

See also

load
getReport
setReport
shareReport
Save and restore the report