Report Manager expects a common URL for loading and saving data:
view:"reports", url:"remote/data"
More information on routes and parameters is located in the Working with Server article.
If you do not have a backend server or require non-standard logic, you can customize the Backend service.
Report Manager expects JSON data where each element of the array is an object with the following fields:
Data example
id: 22
name: "Company per region"
text: "{
"desc":"Created on 10/28/2020",
"data":"companies",
"joins":[...],
"query":"",
"columns":[{"id":"companies.region_id","name":"Region",...],
"group":{"by":[{"id":"companies.region_id"}],"columns":[...]},
"buckets":
[{"column":"sales.product","options":[{"id":"Drinks",
"values":["black tea","espresso","latte","green tea"]},{"id":"Other"}]}],
"meta":{"freeze":1},"sort":null}",
updated: "2020-10-29T12:38:14Z"
Report Manager has the following services for data:
1. Local Data
const local = $$("reports").getService("local");
const modules = local.getModules(); // returns available reports
2. Charts
const charts = $$("reports").getService("charts");
charts.getTypes(); // returns an array with chart type objects
/*
[
{id: "line", value: "Line", icon: "mdi mdi-chart-line"},
{id: "spline", value: "Spline", icon: "mdi mdi-chart-bell-curve-cumulative"},
{id: "area", value: "Area", icon: "mdi mdi-chart-areaspline"},
// other types
]
*/
3. Helpers
const helpers = $$("reports").getService("helpers");
helpers.hasNonDigits(input); // checks whether input contains non-digits
4. Backend
const back = $$("reports").getService("backend");
back.getModels().then((data) => console.log(data));
Study the models folder in the source code for method signatures.
Module is a report configuration. All modules are stored in a DataCollection. The collection is accessible via the getModules() method of the Local Data service.
const modules = $$("myReports").getService("local").getModules();
To make sure that the data are already loaded, use the waitData method to wait for a data promise.
Getting a particular module
const modules = $$("myReports").getService("local").getModules();
modules.waitData.then(function(){
modules.getItem(modules.getFirstId()); // get first module
});
You can get an array of all modules by serializing the collection:
Serializing modules collection
const modules = $$("myReports").getService("local").getModules();
modules.waitData.then(function(){
const arr = modules.serialize(); // get array of modules
/*[
{
id: 22
name: "Company per region"
text: "{
"desc":"Created on 10/28/2020",
"data":"companies",
"joins":[...],
"query":"",
"columns":[{"id":"companies.region_id","name":"Region",...],
"group":{"by":[{"id":"companies.region_id"}],"columns":[...]},
"buckets":
[{"column":"sales.product","options":[{"id":"Drinks",
"values":["black tea","espresso","latte","green tea"]},{"id":"Other"}]}],
"meta":{"freeze":1},"sort":null}",
updated: "2020-10-29T12:38:14Z"
},
...
]*/
});
Models are data sources for reports. All models are stored in a DataCollection. The collection is accessible via the getModels() method of the Local Data service. The method takes the only parameter:
$$("myReports").getService("local").getModels().then(sources => {
// do something with data sources
});
The method returns a hash of data sources:
Data example
{
companies: {id: "companies", name: "Companies", data: [...], refs: [...]},
persons: {id: "persons", name: "Persons", data: [...], refs: [...]},
products: {id: "products", name: "Products", data: [...], [...]},
sales: {id: "sales", name: "Sales", data: [...], refs: [...]}
}
To configure relations for models (data sources) you can set the "refs" property for a model. This is required for joining data after selecting the primary data source.
For example, the "sales" model contains the "refs" array with the following objects:
refs: [
{id: 1, target: "places", source: "sales", name: "Place"},
{id: 2, target: "products", source: "sales", name: "Product"}
{id: 3, target: "persons", source: "sales", name: "Customer"}
],
It means that "sales" can be joined with the "places", "products" and "persons". Note that both the source and the target should have references to each other. The full data example is the following:
{
"persons": {
"id": "persons",
"name": "Persons",
"data": [ /*...*/ ],
"refs": [
{
"id": 3,
"target": "persons",
"source": "sales",
"name": "Customer"
}
]
},
"sales": {
"id": "sales",
"name": "Sales",
"data": [ /*...*/ ],
"refs": [
{
"id": 3,
"target": "persons",
"source": "sales",
"name": "Customer"
}
]
}
}
The model data items (table fields) should also contain the reference information. For example, "place_id" is a reference to the "places" model:
{id: "place_id", name: "Place", type: "reference", ref: "places",…}
Queries are used for filtering reports. All queries are stored in a DataCollection. The collection is accessible via the getQueries() method of the Local Data service.
const queries = $$("myReports").getService("local").getQueries();
To make sure that the data are already loaded, use the waitData method to wait for a data promise.
Getting a particular query
const queries = $$("myReports").getService("local").getQueries();
queries.waitData.then(function(){
queries.getItem(queries.getFirstId()); // get first query
});
You can get an array of all queries by serializing the collection:
Serializing queries collection
const queries = $$("myReports").getService("local").getQueries();
queries.waitData.then(function(){
const arr = queries.serialize(); // get an array of queries
/*[
{
id: 20,
models: ["companies", "persons"],
name: "myFilter",
text: { ...query configuration },
value: "myFilter"
},
...
]*/
});
Related sample: Report Manager: Data Operations
Facets allow you to deliver multiple datasets grouped by particular values for a selected column.
For example, if we want to get faceting by the "Product" column that has the values "Espresso" and "Cappucino", the report should display two tables or charts (each table/chart should contain data for the "Product" facet).
To enable faceting, you should open the Data section of the editor module, switch on Facets and select the faceting column.
Here you can also set the size of facets:
After facets are set, the module configuration object gets two new properties:
The facets array is included into the "data" request. For example, form data can be the following:
columns: ["sales.count","sales.saledate","sales.total"]
facets: ["sales.country_id"]
...
In this case the response is an array of facets. Each facet object includes two properties:
For example:
[
{
data: [{sales.count: "4", sales.saledate: "2022-10-06T00:00:00Z"},…],
facets: [{column: "sales.country_id", value: "1"}]
},
{
data: [{sales.count: "3", sales.saledate: "2012-10-06T00:00:00Z"},…],
facets: [{column: "sales.country_id", value: "2"}]
},
{
data: [{sales.count: "2", sales.saledate: "2012-10-06T00:00:00Z"},…],
facets: [{column: "sales.country_id", value: "3"}]
}
]
Back to top