In the previous article, we described how to connect the pivot table to the JSON data source. To gain even better performance while working with JSON datasets, use Flexmonster Data Server – a special server developed by Flexmonster. This server communicates with the client using the custom data source API – our custom communication protocol allowing you to retrieve already aggregated data from a server to Flexmonster Pivot.
Flexmonster Data Server has the following advantages:
Flexmonster Data Server supports only a specific JSON format – an array of objects, where each object is an unordered set of "key": "value"
pairs. Here is an example:
[
{
"Color" : "green",
"Country" : "Canada",
"State" : "Ontario",
"City" : "Toronto",
"Price" : 174,
"Quantity" : 22
},
...
]
To download the Data Server, you will need Flexmonster CLI — a command-line interface tool for Flexmonster. If needed, install the CLI globally using npm:
npm install -g flexmonster-cli
After that, a new flexmonster
command will be available in the console. Learn more about Flexmonster CLI and its commands in our documentation.
Now follow the steps below to connect to JSON using the Data Server.
If Flexmonster is not yet embedded, set up an empty component in your webpage:
Complete the Quick start guide. Your code should look similar to the following example:
let pivot = new Flexmonster({
container: "pivotContainer",
toolbar: true
});
Complete the Integration with Angular guide. Your code should look similar to the following example:
<fm-pivot
[toolbar]="true">
</fm-pivot>
Complete the Integration with React guide. Your code should look similar to the following example:
<FlexmonsterReact.Pivot
toolbar={true}
/>
Complete the Integration with Vue guide. Your code should look similar to the following example:
<Pivot
ref="pivot"
toolbar>
</Pivot>
The previous step demonstrated how to configure Flexmonster Pivot. Now it’s time to set up Flexmonster Data Server.
Get the Data Server with the following CLI command:
flexmonster add fds -r
The flexmonster add fds
command does the following:
.zip
archive with Flexmonster Data Server.flexmonster-data-server/
folder will appear in your working directory.The -r
option, which is short for --run
, installs the Data Server as a Windows/Unix service and then runs it. Besides, it installs and runs Flexmonster Admin Panel – a graphical user interface for the Data Server.
Now follow the steps below to connect the Data Server to your JSON file.
Now let’s create a new index for the file with your data.
Open Flexmonster Admin Panel and go to Indexes > Add New Index. Then, fill in the following fields:
JSON
.0
, which means the Data Server will not reload the data.Your configurations should look similar to the following:
When the index configuration is complete, click Create. The index will be automatically added to your index pool.
On the client side, the report should be configured as follows:
var pivot = new Flexmonster({
container: "pivotContainer",
toolbar: true,
report: {
dataSource: {
type: "api",
url: "http://localhost:9500",
index: "index-json"
}
}
});
Note The index
must match the name of the index defined in step 3 (e.g., "index-json"
).
When Flexmonster Pivot requests the data, Flexmonster Data Server sends the response and then caches it. In case the component sends the same request once again, the server responds with the data from its cache. The Data Server clears the cache when restarted.
The Data Server’s cache has a memory limit. When the cache does not have enough memory for a new response, the Data Server server deletes one of the previously cached responses.
Note You can manage the cache size via the Cache size limit configuration.
You may be interested in the following articles: