In the previous article, we described how to connect the pivot table to the CSV data source. To gain even better performance while working with CSV 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:
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 CSV using the Data Server.
If Flexmonster is not yet embedded, set up an empty component in your web page:
Complete the Quick start guide. Your code should look similar to the following example:
var 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
The flexmonster add fds
command will download the .zip
archive with Flexmonster Data Server and automatically unpack the files in the current folder. As a result, the flexmonster-data-server/
folder will appear in your working directory.
The Data Server can be configured in the flexmonster-data-server/flexmonster-config.json
file. To learn more about all the available configurations, see the configurations reference.
To set configurations needed for the CSV data source, follow the steps below.
Set the "Type"
property in flexmonster-config.json
to "csv"
. It should be done as follows:
"DataSources": [
{
"Type": "csv"
}
],
Create an index for the file with your data. "Path"
is the path to the file. For example:
"DataSources": [
{
"Type": "csv",
"Indexes": {
"index_csv": {
"Path": "./data/data.csv"
}
}
}
],
In a similar way, additional indexes can be specified:
"Indexes": {
"index_csv": {
"Path": "./data/data.csv"
},
"another_index_csv": {
"Path": "./data/another_data.csv"
}
}
"index_csv"
and "another_index_csv"
are dataset identifiers. They will be used to configure the data source on the client side.
If CSV fields are separated by anything other than ","
, the "Delimiter"
parameter should be specified:
"Indexes": {
"index_csv": {
"Path": "./data/data.csv",
"Delimiter": ";"
}
}
If decimal parts of numbers in the data are separated by anything other than "."
, the "DecimalSeparator"
parameter should be specified:
"Indexes": {
"index_csv": {
"Path": "./data/data.csv",
"Delimiter": ";",
"DecimalSeparator": ","
}
}
If the data contains numbers where groups of digits are separated by anything other than ","
, the "ThousandSeparator"
parameter should be specified:
"Indexes": {
"index_csv": {
"Path": "./data/data.csv",
"Delimiter": ";",
"DecimalSeparator": ",",
"ThousandSeparator": "."
}
}
Start Flexmonster Data Server by running the following command in the console:
flexmonster-data-server.exe
./flexmonster-data-server
As soon as you start Flexmonster Data Server, it automatically preloads the data specified in the "Indexes"
property. Thus, when Flexmonster Pivot requests the data, the server responds with already preloaded data.
The Data Server keeps preloaded data in the server’s RAM, so the number of indexes you can specify is limited by the server’s RAM amount.
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-csv"
}
}
});
index
must match the name of the index defined in step 4 (e.g., "index_csv"
).
When Flexmonster Pivot requests the data, Flexmonster Data Server 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.
You can manage the cache size via the “CacheSizeLimit” property.
You may be interested in the following articles: