Get Free Trial
  1. API reference
Connecting to Data Source
Configuring the component
  • Documentation for older versions
  • Table of contents

    Data source

    The data source is a required part of the ReportObject. Flexmonster supports data from OLAP data sources, SQL databases, CSV and JSON static files, and inline JSON data. Each data source requires specific properties to be set inside the dataSource section of the ReportObject. To see examples of connecting to different data sources, visit the Examples page.

    Read more in the following sections:

    JSON data sources

    JSON data source can be:

    • Files from the local file system.
    • A remote static file.
    • Data generated by a server-side script.
    • Inline JSON.

    Here is a list of dataSource properties used to connect to JSON data sources:

    • browseForFile – Boolean. Defines whether you want to load the file from the local file system (true) or not (false). Default value: false.
    • data – JSON. The inline JSON data.
    • dataRootPath optional — String. If your JSON data is located in a nested property, specify a path to that property in the dataRootPath. See supported JSON formats.
      The dataRootPath works only for the files loaded via the filename property.
      Example: set the dataRootPath to "userData.flexmonsterData" to connect to the following JSON file:
      {
      "creationDate": "01-01-2022",
      "userData" : {
      "flexmonsterData": [
      // your data
      ],

      },

      }
      See the full code on JSFiddle.
    • filename – String. The URL to a JSON file or to a server-side script that generates JSON data.
      If your JSON data is located in a nested property, specify a path to that property in the dataRootPath.
    • mapping optional – MappingObject | String. Allows defining field data types, captions, and multilevel hierarchies, grouping fields under separate dimensions, and setting other view configurations of hierarchies. It can be either an inline MappingObject or a URL to a JSON file with mapping. See an example on JSFiddle.
    • requestHeaders optional – Object. This object allows you to add custom request headers. The object consists of "key": "value" pairs, where "key" is a header name and "value" is its value. Check out a live sample on JSFiddle. Important note: requestHeaders is not saved when obtaining the report via save() and getReport() API calls.
    • type – String. The type of data source. In this case, it is "json". You do not need to explicitly define this property when reading static JSON files with a .json extension.
    • useStreamLoader optional – Boolean. Optimizes the large file processing using the stream loader. When set to true, the stream loader is enabled. Available only when loading files via URL. See an example on JSFiddle. Default value: false.
    • withCredentials optional – Boolean. It indicates whether cross-site Access-Control requests should be made using credentials such as authorization headers (true) or not (false). For more details refer to MDN web docs.
      Setting the withCredentials flag to true is recommended when using Windows authentication and other types of server authentications. When set to false, the browser does not ask for credentials, as well as does not include them in outgoing requests. Default value: false.

    Here is an example of JSON dataset using a file from the local file system:

    report: {
        dataSource: {
            /* Path to the local JSON file */
            filename: "data.json"
        }
    }

    If the data is generated by a server-side script, type must be defined explicitly:

    report: {
        dataSource: {
            type: "json",
            filename: "script_which_returns_json_data"
        }
    }

    Inline JSON:

    report: {
        dataSource: {
            /* jsonData variable contains JSON data */
            data: jsonData
        }
    }

    CSV data sources

    CSV data source can be:

    • A file from the local file system.
    • A remote static file.
    • Data generated by a server-side script.

    Here is a list of dataSource properties used to connect to CSV data sources:

    • browseForFile – Boolean. Defines whether you want to load a file from the local file system (true) or not (false). Default value: false.
    • type – String. The type of data source. In this case, it is "csv". You do not need to explicitly define this property when reading static CSV files with a .csv extension.
    • fieldSeparator optional – String. Defines the specific fields separator to split each CSV row. There is no need to define it if the CSV fields are separated by , or ;. This property is required only if another character separates fields.
      For example, if you use TSV, where a tab character is used to separate fields, then the fieldSeparator parameter should be set to "\t".
      Alternatively, you can specify the field separator in the CSV file’s first row using the sep prefix. Supported prefix formats are the following: sep=fieldSep and "sep=fieldSep". For example:
      sep=|
      Country|Color|Price
      Canada|blue|1000
    • thousandsSeparator optional – String. Defines the specific character used to separate groups of digits in numbers. For example, if commas separate groups of digits in numbers (e.g., 1,000 for one thousand), set thousandsSeparator to ",".
    • filename – String. The URL to a CSV file or to a server-side script that generates CSV data.
    • ignoreQuotedLineBreaks – Boolean. Indicates whether line breaks in quotes should be ignored (true) or not (false). When set to true, CSV parsing is faster. Set it to false only if your data source has important line breaks in quotes. Note that this might slow down CSV parsing a little bit. Default value: true.
    • mapping optional – MappingObject | String. Allows defining field data types, captions, and multilevel hierarchies, grouping fields under separate dimensions, and setting other view configurations of hierarchies. It can be either an inline MappingObject or a URL to a JSON file with mapping. See an example on JSFiddle.
    • requestHeaders optional – Object. This object allows you to add custom request headers. This object consists of "key": "value" pairs, where "key" is a header name and "value" is its value. Check out a live sample on JSFiddle. Important note: requestHeaders is not saved when obtaining the report via save() and getReport() API calls.
    • withCredentials optional – Boolean. It indicates whether cross-site Access-Control requests should be made using credentials such as authorization headers (true) or not (false). For more details refer to MDN web docs.
      Setting the withCredentials flag to true is recommended when using Windows authentication and other types of server authentications. When set to false, the browser does not ask for credentials, as well as does not include them in outgoing requests. Default value: false.

    In the following example data is taken from a CSV file where the colon character (:) is used to separate fields within the row. Line breaks in quotes are not ignored:

    report: {
        dataSource: {
            /* URL or local path to a CSV file */
            filename: 'colon-data.csv',
            fieldSeparator: ':',
            ignoreQuotedLineBreaks: false
        }
    }

    If the data is generated by a server-side script, type must be defined explicitly:

    report: {
        dataSource: {
            type: "csv",
            filename: "script_which_returns_csv_data"
        }
    }

    SQL databases

    Here is a list of dataSource properties used to connect to SQL databases using the custom data source API:

    • type – String. The type of data source. In this case, it is "api".
    • url – String. The path to the API endpoints.
    • index – String. The dataset identifier.
    • mapping optional – MappingObject | String. Allows defining field data types, captions, and multilevel hierarchies, grouping fields under separate dimensions, and setting other view configurations of hierarchies. It can be either an inline MappingObject or a URL to a JSON file with mapping. See an example on JSFiddle.
    • requestHeaders optional – Object. This object allows you to add custom request headers. This object consists of "key": "value" pairs, where "key" is a header name and "value" is its value. Check out a live sample on JSFiddle. Important note: requestHeaders is not saved when obtaining the report via save() and getReport() API calls.
    • withCredentials optional – Boolean. It indicates whether cross-site Access-Control requests should be made using credentials such as authorization headers (true) or not (false). For more details refer to MDN web docs.
      Setting the withCredentials flag to true is recommended when using Windows authentication and other types of server authentications. When set to false, the browser does not ask for credentials, as well as does not include them in outgoing requests. Default value: false.

    Here is an example of how a connection to a relational database is represented in a dataSource object:

    report: {
        dataSource: {
            type: "api",
            url: "https://olap.flexmonster.com:9202/api/cube",
            index: "fm-product-sales"
        }
    } 

    Read more about connecting to SQL databases with the custom data source API here.

    MongoDB databases

    Here is a list of dataSource properties used to connect to a MongoDB database:

    • type – String. The type of data source. In this case, it is "api".
    • url – String. The path to the API endpoints.
    • index – String. The dataset identifier.
    • mapping optional – MappingObject | String. Allows defining field data types, captions, and multilevel hierarchies, grouping fields under separate dimensions, and setting other view configurations of hierarchies. It can be either an inline MappingObject or a URL to a JSON file with mapping. See an example on JSFiddle.
    • requestHeaders optional – Object. This object allows you to add custom request headers. This object consists of "key": "value" pairs, where "key" is a header name and "value" is its value. Check out a live sample on JSFiddle. Important note: requestHeaders is not saved when obtaining the report via save() and getReport() API calls.
    • withCredentials optional – Boolean. It indicates whether cross-site Access-Control requests should be made using credentials such as authorization headers (true) or not (false). For more details refer to MDN web docs.
      Setting the withCredentials flag to true is recommended when using Windows authentication and other types of server authentications. When set to false, the browser does not ask for credentials, as well as does not include them in outgoing requests. Default value: false.

    Here is an example of how a connection to a MongoDB database is represented in a dataSource object:

    report: {
        dataSource: {
            type: "api",
            url: "http://localhost:9204/mongo",
            index: "fm-product-sales"
        }
    }

    The custom data source API

    Here is a list of dataSource properties used to connect to the custom data source API:

    • type – String. The type of data source. In this case, it is "api".
    • url – String. The path to the API endpoints.
    • index – String. The dataset identifier.
    • mapping optional – MappingObject | String. Allows defining field data types, captions, and multilevel hierarchies, grouping fields under separate dimensions, and setting other view configurations of hierarchies. It can be either an inline MappingObject or a URL to a JSON file with mapping. See an example on JSFiddle.
    • requestHeaders optional – Object. This object allows you to add custom request headers. This object consists of "key": "value" pairs, where "key" is a header name and "value" is its value. Check out a live sample on JSFiddle. Important note: requestHeaders is not saved when obtaining the report via save() and getReport() API calls.
    • singleEndpoint – Boolean. When set to true, all custom data source API requests are sent to a single endpoint specified in the url property. Default value: false.
    • withCredentials optional – Boolean. It indicates whether cross-site Access-Control requests should be made using credentials such as authorization headers (true) or not (false). For more details refer to MDN web docs.
      Setting the withCredentials flag to true is recommended when using Windows authentication and other types of server authentications. When set to false, the browser does not ask for credentials, as well as does not include them in outgoing requests. Default value: false.

    Here is an example of how a connection to the custom data source API is represented in a dataSource object:

    report: {
        dataSource: {
            type: "api",
            url: "https://olap.flexmonster.com:9202/api/cube",
            index: "fm-product-sales"
        }
    }

    Check it out on JSFiddle.

    Microsoft Analysis Services

    There are two ways to connect to Microsoft Analysis Services using Flexmonster Pivot:

    1. Via the XMLA protocol – an industry standard for data access in analytical systems. Works for multidimensional models only.
    2. Via Flexmonster Accelerator – a special server-side utility developed by Flexmonster. Works for both multidimensional and tabular models.

    Here is a list of dataSource properties used to connect to Microsoft Analysis Services:

    • catalog – String. The data source catalog name.
    • cube – String. The given catalog’s cube’s name.
    • dataSourceInfo optional – String. The service info.
    • type – String. The type of data source. In this case, it is "microsoft analysis services".
    • proxyUrl – String. The path to the proxy URL. Both tabular and multidimensional model types are supported.
    • binary optional – Boolean. A flag to use Flexmonster Accelerator instead of the XMLA protocol.
    • effectiveUserName optional – String. Use when an end-user identity must be impersonated on the server. Specify the account in a domain\user format.
    • localeIdentifier optional – Number. The Microsoft locale ID value for your language.
    • mapping optional – MappingObject | String. Allows defining field data types, captions, multilevel hierarchies, grouping fields under separate dimensions, and setting other view configurations of hierarchies. It can be either an inline MappingObject or a URL to a JSON file with mapping. See an example on JSFiddle.
    • roles optional – String. A comma-delimited list of predefined roles to connect to a server or a database using the permissions defined by that role. If this property is omitted, all roles are used and the effective permissions are the combination of all roles. For example, to combine "admin" and "manager" roles, set the roles property like so: roles: "admin,manager".
    • subquery optional – String. This parameter allows setting a server-side filter to decrease the size of the response from the OLAP cube. For example, to show reports for only one specific year set the subquery like so: "subquery": "select {[Delivery Date].[Calendar].[Calendar Year].&[2008]} on columns from [Adventure Works]". See an example on JSFiddle.
    • requestHeaders optional – Object. This object allows you to add custom request headers. This object consists of "key": "value" pairs, where "key" is a header name and "value" is its value. Check out a live sample on JSFiddle. Important note: requestHeaders is not saved when obtaining the report via save() and getReport() API calls.
    • useGranularityNamesForDateFilters optional — Boolean. Allows adjusting date filters to the cube structure.
      If set to true, date filters use granularityNames. If set to false, date filters use the unique name of the hierarchy being filtered.
      Default value: true.
    • withCredentials optional – Boolean. It indicates whether cross-site Access-Control requests should be made using credentials such as authorization headers (true) or not (false). For more details refer to MDN web docs.
      Setting the withCredentials flag to true is recommended when using Windows authentication and other types of server authentications. When set to false, the browser does not ask for credentials, as well as does not include them in outgoing requests. This property is available for both XMLA protocol and Flexmonster Accelerator. Default value: false.

    Here is an example of how the connection to SSAS via XMLA is represented in dataSource:

    report: {
        dataSource: {
            type: "microsoft analysis services",
            // URL to msmdpump.dll 
            proxyUrl: "https://olap.flexmonster.com/olap/msmdpump.dll",
            catalog: "Adventure Works DW Standard Edition",
            cube: "Adventure Works",
            // Microsoft Locale ID Value for French 
            localeIdentifier: 1036, 
            // roles from SSAS 
            roles: "admin,manager",
            subquery: "select {
                    [Delivery Date].[Calendar].[Calendar Year].&[2008]
                    } on columns from [Adventure Works]"
        }
    }

    Check it out on JSFiddle.

    Here is an example of how the connection to SSAS via Flexmonster Accelerator is represented in dataSource:

    report: {
        dataSource: {
            type: "microsoft analysis services",
            proxyUrl: "http://localhost:50005",
            catalog: "Adventure Works DW Standard Edition",
            cube: "Adventure Works",
            binary: true,         
            // Microsoft Locale ID Value for French 
            localeIdentifier: 1036,
            subquery: "select {
                    [Delivery Date].[Calendar].[Calendar Year].&[2008]
                    } on columns from [Adventure Works]" 
        }
    }

    You can read all the details about the Accelerator here.

    Elasticsearch

    Here is a list of dataSource properties used to connect to Elasticsearch:

    • type – String. The type of the data source. In this case, it is "elasticsearch".
    • subquery optionalBoolQueryObject. This parameter allows setting a server-side filter to decrease the size of the response from the server. See an example on JSFiddle.
    • mapping optional – MappingObject | String. Allows customizing hierarchies’ captions, formats, time zones, control fields’ visibility, and more. It can be either an inline MappingObject or a URL to a JSON file with mapping. See an example on JSFiddle.
    • node – String. The URL string for the connection.
    • index – String. The name of the Elasticsearch index to connect to.
    • requestHeaders optional – Object. This object allows you to add custom request headers. This object consists of "key": "value" pairs, where "key" is a header name and "value" is its value. Check out a live sample on JSFiddle. Important note: requestHeaders is not saved when obtaining the report via the save() and getReport() API calls.
    • withCredentials optional – Boolean. It indicates whether cross-site Access-Control requests should be made using credentials such as authorization headers (true) or not (false). For more details refer to MDN web docs.
      Setting the withCredentials flag to true is recommended when using Windows authentication and other types of server authentications. When set to false, the browser does not ask for credentials, as well as does not include them in outgoing requests. Default value: false.

    Here is an example of how a connection to Elasticsearch is represented in a dataSource object:

    report: {
        dataSource: {
            type: "elasticsearch",
            node: "https://olap.flexmonster.com:9200",
            index: "fm-product-sales"
        }
    }

    Try the example on JSFiddle.

    Change the data source using the Toolbar

    Use the Connect option to choose another data source or Open to load another report at runtime. Use Save to save the report with the current data source.

    dataSource

    Data in the pivot table will be updated and saved within the report.

    Data source via API

    The API calls connectTo(), load(), and open() are used to change the data source at runtime. The API call save() is used to save the report.