Dataset Tag in QPR UI

From Mea Wiki
Jump to navigation Jump to search

Dataset tag is used to get a dataset into a JSON format to be used for example in a Chart or Data Grid JSON settings. Data is presented in their original datatypes in the JSON (more information: https://www.w3schools.com/js/js_json_datatypes.asp). Following datatypes can be shown in the JSON: string, integer, double, boolean and datetime. Datetime is presented as integer in milliseconds from 01 January 1970 00:00:00 UTC as JSON doesn't support dates directly. Dataset tag parameters:

Tag parameter Description
identifier Used dataset identifier. The dataset may exist in the same or upper level in the UI elements hierarchy. An error message is shown if the referenced dataset doesn't exist.
grouping When grouping is defined, JSON is structured in a two level hierarchy (see the example 3 below). The grouping is defined using format [Group column in dataset];[Group property in JSON];[Inner array property in JSON]. In the hierarchy the outer level contains an object array where the objects have two properties: the defined Group property in JSON and Inner array property in JSON. Group property in JSON contains the group name, and Group property in JSON contains an object array where there is data belonging to that single group.
additionalJson JSON structure that is added (merged) to the JSON that is generated by the dataset tag. The additional JSON must be an object array. When defined in the tag, the JSON definition needs to be escaped. Example:
additionalJson="[{\"property1\":\"value1\"},{\"property2"\:\"value2\"},{\"property3"\:\"value3\"}]"
(other parameters) All other parameters define column mappings from the dataset to the JSON presentation. Parameter name is the column name in the formatted JSON and parameter value is the dataset column name. All unmapped columns in the dataset are mapped with same names in JSON. Empty value means that if the dataset contains the defined column, it is not mapped. If referenced column is not found, an error is returned.

Example 1

<#dataset identifier="scorecards" name="scorecardName" x="" y="revenue" color="statusColor">

Examples 2

If there is a dataset with columns A, B and C, and there is a tag

<#dataset identifier="datasetname" D="A" B="">

the resulting JSON contains columns D and C. Column A as mapped with the name D, column B is not mapped at all and C as mapped with the same name.

Example 3: grouping

There is the following dataset with identifier MetricsQuery (shown here in the CSV format):

Country;Year;Efficiency
India;2015;28
India;2016;25
India;2017;26
Germany;2015;31
Germany;2016;28
Germany;2017;30
England;2015;36
England;2016;32
England;2017;34

With tag

<#dataset identifier="MetricsQuery" grouping="Country;name;data" x="Year" y="Efficiency">

the result is as follows:

[
  {
    "name": "India",
    "data": [{"x": 2015, "y": 28}, {"x": 2016, "y": 25}, {"x": 2017, "y": 26}]						 
  },						
  {
    "name": "Germany",
    "data": [{"x": 2015, "y": 31}, {"x": 2016, "y": 28}, {"x": 2017, "y": 30}]					 
  },
  {
    "name": "England",
    "data": [{"x": 2015, "y": 36}, {"x": 2016, "y": 32}, {"x": 2017, "y": 34}]					 
  }
]

Note about console errors regarding datasets:

When using the Dataset tag in the JS code of a HTML Object, we have experienced some errors / warnings in the Console tab log of the browser Developer Tools when navigating to another dashboard. If we are using the Dataset Tag in the previous dashboard (the one we are navigating from), the UI requests that dataset again to the server, but in the new dashboard there is not such defined dataset identifier (in the Dataset tab of the view), so the UI throws the following error / warning when it is parsing the JS code '#invalid dataset tag identifier'.
If we are using the Dataset tag like this in JS:

    var JSDataSet = <#dataset identifier="datasetIdentifier">;

the browser will throw an error.

We can handle the dataset tag in JS as a String rather than an Array, so the browser will not throw and error if the Dataset does not exist. Additionally, we can control if it exists or not in order to assign it to a variable:

  var JSDataSet = [];
  if ('<#dataset identifier="datasetIdentifier">' != '#invalid dataset tag identifier') JSDataSet = JSON.parse('<#dataset identifier="datasetIdentifier">');