This tutorial describes how to integrate Flexmonster Pivot with Electron.js – a JavaScript framework that allows creating cross-platform desktop applications.
npm install -g flexmonster-cli
Create the sample project with the following CLI command:
flexmonster create electron -r
The flexmonster create electron command does the following:
.zip archive with the sample Electron project from GitHub.flexmonster-electron-project/ folder will appear in your working directory.The -r option, which is short for --run:
package.json.Once the command is executed, a desktop application with the pivot table embedded will be launched.
This guide is based on the Electron quick start tutorial. Complete the following steps to integrate Flexmonster Pivot into a new Electron.js application.
Skip this step if you already have an Electron app.
Step 1.1. Create an empty folder for the new Electron application (e.g., pivot-electron) and run the following command from this folder:
npm init
This command will ask you several questions to generate a basic package.json file. For simplicity, press Enter each time to choose the default options.
The newly created package.json file should look similar to the following:
{
"name": "pivot-electron",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}Step 1.2. Install Electron.js in the project by running the following command in the console:
npm install electron
Step 1.3. By default, the npm start command runs the application with Node.js. To run the application with Electron, add the following start script to package.json:
"scripts": {
"start": "electron .",
"test": "echo \"Error: no test specified\" && exit 1"
}Step 1.4. HTML files define the Electron application’s user interface. Create an HTML file (e.g., index.html) with a simple markup:
<!DOCTYPE html> <html> <head> <title>Pivot table for Desktop</title> </head> <body> </body> </html>
Step 1.5. As specified in the package.json file, the entry point for the application is the index.js file. Create a simple index.js file that waits for the application to be ready and then opens the window:
const { app, BrowserWindow } = require('electron')
function createWindow () {
// create the browser window
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
// load the previously created index.html file
win.loadFile('index.html')
}
// open the window when the application is ready
app.whenReady().then(createWindow)Install Flexmonster by running this CLI command inside your Electron.js project:
flexmonster add js-flexmonster
The add command installs the flexmonster npm package to node_modules/ and adds it as an npm dependency to package.json.
In the index.html file, add a container for Flexmonster inside the <body> tag:
<body>
<div id="pivotContainer"></div>
</body> Create a new .js file (e.g., pivot.js) for Flexmonster. Include the Flexmonster npm module into it and create a new Flexmonster instance:
require('flexmonster');
const pivot = new Flexmonster({
container: "pivotContainer",
toolbar: true,
report: "https://cdn.flexmonster.com/github/demo-report.json"
});Include the script to embed Flexmonster to the index.html file:
<body>
<div id="pivotContainer"></div>
<script src="./pivot.js"></script>
</body>
Include Flexmonster styles into the index.html file as follows:
<head>
<title>Pivot table for Desktop</title>
<link rel="stylesheet" type="text/css"
href="node_modules/flexmonster/flexmonster.min.css"
/>
</head> Run the project from the console with the following command:
npm start
A desktop application with the embedded pivot table will be launched.
To shut down the application, close the application window or press Ctrl + C (Control + C on macOS) in the console.
If you run into any issues during the integration, visit our troubleshooting page.
Can't find your answer?
Visit the FAQ
Flexmonster Pivot Table & Charts is a JavaScript pivot table component for adding interactive reporting and data analysis to web applications. Users can summarize, filter, sort, and explore data in pivot tables and charts, drill into results, and export reports.
Flexmonster works in plain JavaScript and TypeScript projects. It also integrates with React, Next.js, Angular, Vue, Blazor, and other technologies. See all integration options.
Flexmonster supports JSON and CSV files, SQL databases, MongoDB, Elasticsearch, and Microsoft Analysis Services (SSAS). You can also connect other data sources through your own backend. See supported data sources.
Flexmonster offers licenses for internal corporate use, SaaS products, and OEM distribution. Pricing varies by license and plan. SaaS projects can also use the free SaaS Entry license during development. Learn more on the pricing page.
Yes. Flexmonster offers a 30-day free trial that lets you evaluate all its features. No credit card is required. The trial version has a watermark.
To get started with Flexmonster, follow our integration guide.