Creating Report with Relations at Runtime
Our sample projects and report templates can help you learn the basics of working with our products.Two data sources can be linked by a relation defined in code, so a master-detail report resolves child rows for each parent.
Create parent and child sources.
How it works. The relation lets a detail band filter child rows by the current parent row, producing master-detail output from code-built sources.
Create parent and child sources.
StiDataTableSource parent = new StiDataTableSource("Demo.Parent", "Parent", "Parent");
parent.getColumns().add(new StiDataColumn("cId", "cId", StiSystemType.getSystemType("System.Object")));
StiDataTableSource child = new StiDataTableSource("Demo.Child", "Child", "Child");
child.getColumns().add(new StiDataColumn("cId", "cId", StiSystemType.getSystemType("System.Object")));Define the relation between them.ArrayList<String> cols = new ArrayList<String>();
cols.add("cId");
StiDataRelation rel = new StiDataRelation("Relation", parent, child, cols, cols);
report.getDictionary().getRelations().add(rel);StiDataRelation(name, parent, child, parentColumns, childColumns)— links the two sources on their key columns.getDictionary().getRelations().add(rel)— registers the relation so nested detail bands can use it.
How it works. The relation lets a detail band filter child rows by the current parent row, producing master-detail output from code-built sources.