Relation's name and alias are generated automatically

Stimulsoft Reports.JS discussion
Post Reply
natra
Posts: 2
Joined: Thu Jul 04, 2019 9:49 am

Relation's name and alias are generated automatically

Post by natra »

Hello,

We've bought Report.JS package and we've encountered an issue with creating relations between data sources.

In our code we are specifying relation's name and alias in the StiDataRelation constructor, but it's not reflected in the dictionary after execution of the regRelation function.

Here is a sample code:

Code: Select all

  const designer = new Stimulsoft.Designer.StiDesigner(options, 'StiDesigner', false);

  // Load report
  const report = new Stimulsoft.Report.StiReport();
  report.load(input.reportBody);
  designer.report = report;

  // Load data as dictionary
  const dataSet = new Stimulsoft.System.Data.DataSet("SimpleDataSet");
  const relations = input.data.relations;
  delete input.data.relations;
  dataSet.readJson(input.data);
  
  // Handle relations
  report.regData(dataSet.dataSetName, "", dataSet);
  report.dictionary.synchronize();

  const newRelation = new Stimulsoft.Report.Dictionary.StiDataRelation(
      "GroupToProduct[products]",
      "products", // desired name
      "products", // desired alias
      report.dictionary.getDataSourceByName("Group"),
      report.dictionary.getDataSourceByName("Product"),
      ["productGroup"],
      ["id"]
  );
    
  report.dictionary.regRelation(newRelation, false);
    
  report.dictionary.synchronize();

And here is an example of created relation:

Screenshot 2019-07-04 at 12.05.43.png
Screenshot 2019-07-04 at 12.05.43.png (18.56 KiB) Viewed 1623 times

The name and alias are set to the name of a parent source name, no matter what is putted in the StiDataRelation constructor.

How can we set the name and alias correctly?

Thank you,
Rafał
natra
Posts: 2
Joined: Thu Jul 04, 2019 9:49 am

Re: Relation's name and alias are generated automatically

Post by natra »

And here is a full working demo:

Code: Select all

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Create report designer and show it immediately</title>

    <!-- Report designer Office2013 White Blue style -->
    <link href="https://raw.githack.com/stimulsoft/Samples-JS/master/JavaScript/css/stimulsoft.designer.office2013.whiteblue.css" rel="stylesheet">
    <link href="https://raw.githack.com/stimulsoft/Samples-JS/master/JavaScript/css/stimulsoft.viewer.office2013.whiteblue.css" rel="stylesheet">

    <!-- Stimusloft Reports.JS -->
    <script src="https://raw.githack.com/stimulsoft/Samples-JS/master/JavaScript/scripts/stimulsoft.reports.js" type="text/javascript"></script>
    <script src="https://raw.githack.com/stimulsoft/Samples-JS/master/JavaScript/scripts/stimulsoft.viewer.js" type="text/javascript"></script>
    <script src="https://raw.githack.com/stimulsoft/Samples-JS/master/JavaScript/scripts/stimulsoft.designer.js" type="text/javascript"></script>
</head>
<body>
<div id="order-confirmation"></div>

<script type="text/javascript">
  function StiHelper(timeout, context = 'default') {
    this.timeout = timeout;
    this.context = context;
  }

  const options = new Stimulsoft.Designer.StiDesignerOptions();
  options.appearance.fullScreenMode = true;
  options.toolbar.showSendEmailButton = true;
  options.toolbar.showFileMenu = false;
  options.viewerOptions.toolbar.showOpenButton = false;
  options.viewerOptions.toolbar.showSendEmailButton = true;

  const designer = new Stimulsoft.Designer.StiDesigner(options, 'StiDesigner', false);

  const jsHelper = new StiHelper(30);

  // Load report
  const report = new Stimulsoft.Report.StiReport();
  // report.load(input.reportBody);

  // Load data as dictionary
  const dataSet = new Stimulsoft.System.Data.DataSet("DataSet");
  const data = {
    Table1: {
      id: 1,
    },
    Table2: {
      id: 2,
      table1: 1
    }
  };
  dataSet.readJson(data);

  // Handle relations
  report.regData(dataSet.dataSetName, "", dataSet);
  report.dictionary.synchronize();

    const newRelation = new Stimulsoft.Report.Dictionary.StiDataRelation(
      "Table1ToTable2[children]",
      "children", // desired name
      "children", // desired alias
      report.dictionary.getDataSourceByName("Table1"),
      report.dictionary.getDataSourceByName("Table2"),
      ["id"],
      ["table1"]
    );

    report.dictionary.regRelation(newRelation, false);

  report.dictionary.synchronize();

  designer.report = report;

  designer.renderHtml("order-confirmation");
</script>
</body>
</html>
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Relation's name and alias are generated automatically

Post by Lech Kulikowski »

Hello,

To add relation from code, you can use the following code:

Code: Select all

var dataRelation = new Stimulsoft.Report.Dictionary.StiDataRelation("MyRelation", "MyRelation", "MyRelation", report.dictionary.dataSources.getByName("Categories"), report.dictionary.dataSources.getByName("Products"), ["CategoryID"], ["CategoryID"]);
report.dictionary.relations.add(dataRelation); 
Thank you.
Post Reply