I've been researching how to generate a report in our application which has a C# .NET 6 Web API project and a React front-end, both fully disconnected. I've been trying various things out and keep running into roadblocks. Here are some issues I've hit:
- I can't get the report designer to recognize our domain project (I'm trying the object data source) because it's targeting .NET 6. I'm not able to convert it to .NET Standard. I reviewed the examples in the Telerik directory but the .NET Core samples don't seem to reference the DataBinding sample, which is the one that uses an object data source. There is also a .NET Standard project called SpeakerObjects which I see referenced but I don't see any reports that use those objects as a data soure
- I tried a web service data source as well but it wasn't obvious how to pass the JWT to the service for authentication when designing the report.
Generally speaking, the way I was hoping this worked is that I'd design a report template against a generic data source. E.g. the report fields would be bound to loosely-typed data fields like customer.FirstName, customer.SSN, customer.PhoneNumber, etc. That is, I wouldn't need to wire the report up to a specific data source for the purpose of designing it. Then in the backend, I'd retrieve the data I need, take the report template file and shove the data into it at runtime using the Telerik packages. It would do its magic and bind the objects to the fields and return a PDF. But I'm having a hard time with that because the report designer (both Visual Studio and stand-alone) seem to really want to know what the data looks like while I'm designing and I can't get it hooked up to either our domain project or our API to do that.
For .NET Core projects, we highly recommend the usage of .TRDP/.TRDX reports. An example with the Speakers objects can be found in the installation folder of Telerik Reporting:
C:\Program Files (x86)\Progress\Telerik Reporting R2 2022\Report Designer\Examples -> Speakers report
When it comes to passing the JWT token, you can test doing that by setting the authenticationToken property of the viewer.
Thanks for the info. I think I understand how that would work. When we need to run the report, we'd load the .TRDP/.TRDX file and set the data source to our business objects using an appropriate ReportSource object and then use a ReportProcessor to render it.
Assuming that's correct, I assume the report does not need to know the schema of the business objects at design time. And if so, are there any restrictions on the business objects? The samples suggest you need to decorate them with a [DataObject] attribute but I hope that's only required for design time support so you can preview them, correct?
In general, you only need to know the names of the fields in design time. For example, add a TextBox with =Fields.name, then in runtime, when you populate the report with data, the textbox will display the names from the datasource.
If you need to create the tables dynamically, I would recommend checking the following resources:
- How to Create a Dynamic Table/Crosstab/List item (contains a sample report)
- How to add multiple tables dynamically based on the data source (contains a sample report)
- How to modify table with preset styles and width dynamically