Parent Detail Report - create relation in code
Posted: Fri Sep 13, 2019 5:17 am
Hi,
I have a report that uses a parent-detail relationship between two databands, which works fine when I set up the datasource and relationship in the actual .mrt file, but when I try to do it via javascript it doesn't work.
I get the data from a back-end database and return it as JSON.
All the data in the report loads but the detail part is showing all records for each master heading rather than just the specific headings. When I try to add a data Relation it errors so I haven't got the code right.
Here is my code:
var test = JSON.stringify(this.state.data);
var dataSet = new Stimulsoft.System.Data.DataSet("test");
dataSet.readJson(test)
report.regData(dataSet.dataSetName, "", dataSet);
report.dictionary.connect(false);
report.dictionary.synchronize();
var parentId: string[] = [];
parentId.push("id");
var childId: string[] = []
childId.push("headerId")
var dataRelation = new Stimulsoft.System.Data.DataRelation("Relation", report.dictionary.dataSources["scopeOfWorks"], report.dictionary.dataSources["scopeOfWorks_scope"], parentId, childId);
report.dictionary.regRelation(dataRelation.relationName, "", dataRelation);
viewer.report = report;
viewer.renderHtml('viewer');
Attached: A sample of Json that is similar to what I am returning from the database, and the actual .mrt file I am using
I have a report that uses a parent-detail relationship between two databands, which works fine when I set up the datasource and relationship in the actual .mrt file, but when I try to do it via javascript it doesn't work.
I get the data from a back-end database and return it as JSON.
All the data in the report loads but the detail part is showing all records for each master heading rather than just the specific headings. When I try to add a data Relation it errors so I haven't got the code right.
Here is my code:
var test = JSON.stringify(this.state.data);
var dataSet = new Stimulsoft.System.Data.DataSet("test");
dataSet.readJson(test)
report.regData(dataSet.dataSetName, "", dataSet);
report.dictionary.connect(false);
report.dictionary.synchronize();
var parentId: string[] = [];
parentId.push("id");
var childId: string[] = []
childId.push("headerId")
var dataRelation = new Stimulsoft.System.Data.DataRelation("Relation", report.dictionary.dataSources["scopeOfWorks"], report.dictionary.dataSources["scopeOfWorks_scope"], parentId, childId);
report.dictionary.regRelation(dataRelation.relationName, "", dataRelation);
viewer.report = report;
viewer.renderHtml('viewer');
Attached: A sample of Json that is similar to what I am returning from the database, and the actual .mrt file I am using