Registering Data from Code
Our sample projects and report templates can help you learn the basics of working with our products.Instead of a database connection, you can pass an in-memory DataSet directly to the report.
Preparing the data. Read or create the data source, register it in the report dictionary, synchronize the schema, and render with the supplied records.
The
Preparing the data. Read or create the data source, register it in the report dictionary, synchronize the schema, and render with the supplied records.
@Component({
selector: "registering-data-from-code",
imports: [Viewer],
template: `
<div class="container">
<div class="container-button">
<button (click)="buttonXmlClick()" class="button" title="Using regData() method for registering XML data">Register XML Data</button>
<button (click)="buttonJsonClick()" class="button" title="Using regData() method for registering JSON data">Register JSON Data</button>
</div>
<div>
<sti-viewer [report]="report"></sti-viewer>
</div>
</div>`,
styleUrls: ['../styles.css']
})
export class RegisteringDataFromCode {
report = new Stimulsoft.Report.StiReport();
updateReport(dataSet: Stimulsoft.System.Data.DataSet) {
this.report = new Stimulsoft.Report.StiReport();
this.report.loadFile("Reports/TwoSimpleLists.mrt");
this.report.dictionary.databases.clear();
this.report.regData("Demo", "Demo", dataSet);
}
buttonXmlClick() {
var dataSet = new Stimulsoft.System.Data.DataSet();
dataSet.readXmlSchemaFile("Data/Demo.xsd");
dataSet.readXmlFile("Data/Demo.xml");
this.updateReport(dataSet);
}
buttonJsonClick() {
var dataSet = new Stimulsoft.System.Data.DataSet();
dataSet.readJsonFile("Data/Demo.json");
this.updateReport(dataSet);
}
constructor() {
}
}The
DataSet is populated with readXmlFile/readXmlSchemaFile or readJsonFile, then handed to the report through regData(). Clearing dictionary.databases first removes the design-time connection.