Flexmonster Software License Agreement (“Agreement”) has been revised and is effective as of January 8, 2025.
The following modifications were made:
The modified version of Agreement is available here.
Downloading, installing, and/or continuing to use Flexmonster Software after January 8, 2025, constitutes Licensee’s acceptance of the terms and conditions of the modified version of Agreement. If Licensee does not agree to any of these terms and conditions, they must cease using Flexmonster Software and must not download, install, use, access, or continue to access Flexmonster Software. By continuing to use Flexmonster Software or renewing the license or maintenance after the effective date of these modifications to Agreement, Licensee accepts and agrees to be bound by the terms and conditions of the modified Agreement.
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.
The saved report can contain only configurations set in the ReportObject and GlobalObject, for example:
The configurations listed below are not saved:
Reports are saved in JSON format. You can save your report:
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"
});
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 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.
When saving the report as a ReportObject, you can:
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
}
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:
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
}
}
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:
options.defaultHierarchySortName
in the report above).localization
in the report above).options.readOnly
in the report above). options.grid.showHeaders
in the report above).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.withDefaults: true
is used.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:
You can restore a report in the following ways:
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.
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.
When restoring the report from a ReportObject, you can:
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);
}
1) Save the report with global and default configurations:
pivot.save({
withGlobals: true,
withDefaults: true
});
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);
}
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.
You may be interested in the following articles: