This example shows how to use business objects in the report. First, load scripts:
@using Stimulsoft.Base
@using Stimulsoft.Report
@using Stimulsoft.Report.Blazor
@using Stimulsoft.Report.Web
Next, add report designer:
<StiBlazorDesigner Report="@Report" OnSaveReport="@OnSaveReport" />
After that, create empty report object and load report template:
@code
{
//Report object to use in designer
private StiReport Report;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
//Create empty report object
this.Report = new StiReport();
//Load report template
var reportBytes = await Http.GetByteArrayAsync("Reports/BusinessObjects.mrt");
this.Report.Load(reportBytes);
...
Then, create and register business object:
...
//Create business object
var list = GetBusinessObject();
//Register business object in the report template
this.Report.RegBusinessObject("MyList", list);
this.Report.Dictionary.Synchronize();
}
...
Next, create save method:
...
private void OnSaveReport(StiSaveReportEventArgs args)
{
var reportJson = args.Report.SaveToJsonString();
await Task.CompletedTask;
}
...
Finally, fill data to business objects:
...
//Business objects
public class BusinessEntity
{
public string Name { get; set; }
public string Alias { get; set; }
public BusinessEntity(string name, string alias)
{
Name = name;
Alias = alias;
}
}
private System.Collections.ArrayList GetBusinessObject()
{
var list = new System.Collections.ArrayList();
list.Add(new BusinessEntity("name1", "alias1"));
list.Add(new BusinessEntity("name2", "alias2"));
list.Add(new BusinessEntity("name3", "alias3"));
return list;
}
}
На скриншоте ниже Вы можете увидеть результат выполнения данного кода: