Telerik Reporting for Blazor Native use list of objects as data source in TRDP report

1 Answer 485 Views
DataSource Object DataSources Report Parameters Report Viewer - Blazor
Roman
Top achievements
Rank 1
Iron
Roman asked on 12 Apr 2023, 12:38 PM

Hello

I'm using a Telerik Blazor Native ReportViewer and try to display an existing report (created with the Telerik Report Designer) with dynamic data. This works great for simple data types such as strings, integers, floats etc. But I want to send a list (or an array if lists are not possible) of custom objects to the report and display it in e.g. a table.
From what I've read in your documentations I have to use a data source in the report designer. So I try to add a Object Data Source. I'm already stuck at the first step, where I have to choose a business object. The list is empty and I cannot select anything. If I understand this correct, then a business object is just an object/a class that contains some properties that I want to use in the report, is that correct? So I compiled a test application (class library .NET 7) with a file containing two classes.

namespace TestBusinessObject
{
    public class MyDataSource
    {
        public string ArtName { get; set; }
        public string Measures { get; set; }
        public string ArtNo { get; set; }
        public int Quantity { get; set; }
    }

    public class AnotherClass
    {
        public string Name { get; set; }
        public int Number { get; set; }
    }
}

I followed the steps in this article and copied my compiled DLL to the report designer's location and changed the config of the Telerik.ReportDesigner.exe.config. But there is still no business object to choose in the report designer.





I'm not even sure if this is the right way to achieve what I want, but it looks the most promising and makes the most sense to me.

Can you tell me what I'm doing wrong?

Kind Regards,
Roman

1 Answer, 1 is accepted

Sort by
1
Accepted
Dimitar
Telerik team
answered on 14 Apr 2023, 01:10 PM

Hello Roman,

Thank you for the provided information!

.NET Compatibility

If the class library "TestBusinessObject" was indeed built for .NET 7, that would be the main reason for the data not showing up in the designer.

The older .NET Framework Standalone Report Designer application can resolve only assemblies built for .NET Framework or for .NET Standard up to 2.0

The solution here is to either use .NET Stanard 2.0 for your class library so that it will be compatible with the .NET Framework designer and your .NET Core projects, or use the new .NET 6-based Standalone Report Designer that is located inside the ".NET" folder from your last image. However, since it is built for .NET 6 it also won't be as straightforward to load a .NET 7 assembly but we have a KB article for that - Loading .NET 7 assemblies in the Standalone Report Designer for .NET - Telerik Reporting.

ObjectDataSource Examples

I would also like to recommend you a couple of examples of how the ObjectDataSource may be set up:

Generally, the idea is that you will have methods in your code that will return instances of your classes that are created by you manually in the code. IList objects are also supported. You may see the full list of supported types in the ObjectDataSource Component at a Glance - Telerik Reporting article.

Wrapping Up

The last thing I want to mention is that once the report designer is correctly set up and you are able to use your ObjectDataSource as expected when you wish to display that report in your application, the assembly with the data should also be referenced by your application, see Configuration for the Report Viewer/Web Report Designer for details.

I hope that the provided information will help, please do not hesitate to let me know if you have any additional questions.

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Roman
Top achievements
Rank 1
Iron
commented on 17 Apr 2023, 09:02 AM

Hi Dimitar

Thanks for your response. I compiled it as a .NET Standard 2.0 library and it's now visible in the Report Designer, great!

Now I'm wondering how the whole usage of this works. How can I prepare the data in my Blazor WASM project (where the report viewer is) and then send it to the report and use this data as the DataSource? I'm not really getting that. Or is this a complete wrong approach and need to be done in another way?

Thanks & Best Regards,
Roman

Dimitar
Telerik team
commented on 19 Apr 2023, 12:51 PM

Hi Roman, 

If I understand correctly, you would like to pass the data from the front end, the Blazor WASM application, is that correct?

If that is indeed the case, then the ObjectDataSource component might not be what you need to use. The idea of this component is not to interact with the outside world besides using data source parameters. The idea of this data source component is that you get the data you need through code and then provide it to the report but there is no communication with the report viewer itself and thus with the Blazor WASM application. 

If you do not need to pass the whole data from the Blazor WASM application, I suggest looking into the Using Parameters with the ObjectDataSource Component explained - Telerik Reporting article.  For example, if your front end holds stuff like some IDs, Dates, etc. you can pass them to your ObjectDataSource component's methods through report parameters whose values are then provided to the ObjectDataSource parameters. Then, you can change your data in code depending on what the provided values are.

If instead, you need to pass the whole data through the Blazor report viewer and the Blazor WASM application, you will need to use a more hack-ish approach. You would need to serialize your data on the front end, and you would need to pass the JSON string to the report through a report parameter. Please see the Setting the content of JsonDataSource through report parameter - Telerik Reporting KB article for an example of this.

If your scenario is not covered in any of the above, please share more information about it and I will see if there are other approaches that you can use.

Thank you for using Telerik Reporting!

Roman
Top achievements
Rank 1
Iron
commented on 24 Apr 2023, 08:38 AM

Hi Dimitar

Yes, I need to pass my data during runtime from my Blazor WASM application to the report. I tried your solution but I'm missing one part I can't figure out. I serialize my list of objects as a json string. It looks like this:

[{"ArtName":"Mesa","Measures":"500 mm","ArtNo":"1234.AA","Quantity":1},{"ArtName":"Telvino","Measures":"357 mm","ArtNo":"555.BC","Quantity":7},{"ArtName":"Smart Case","Measures":"612 mm","ArtNo":"0507.LB","Quantity":3}]

And in my report designer I added a JsonDataSource. But I don't really get the "Source" property of JsonDataSource. It opens a window where I can set a data selector, but I don't really know what to put there.

In my table I added a binding to a textbox:

Property path: Value
Expression: =Fields.ArtNo

And I also added a parameter "TestSource" of type string. But this parameter is not connected to the Json DataSource yet, since I don't know how to do this.

Can you explain this to me please?

Thanks & Best Regards,
Roman

Dimitar
Telerik team
commented on 25 Apr 2023, 11:50 AM

The JsonDataSource can be created with empty data or you may use a sample JSON that has the same structure as the real deal.

The approach from the Setting the content of JsonDataSource through report parameter - Telerik Reporting KB article requires the binding to the set on the data item that used the JsonDataSource. Basically, the process is the following:

  1. Create JsonDataSource with dummy or no data
  2. Create the Report Parameter that will pass the JSON string
  3. Set the JsonDataSource to a data item, such as a table, for example
  4. Create the binding on the table report item itself. Note that the DataSource.Source has to be manually written in the binding path.

Basically, the binding is applied to the report item itself and not to the data source component and only data items can be bound. The Textbox is not a data item which is why your data binding did not work. Instead, you add a table, list, crosstab, graph, or subreport and you bind their DataSource. Then you may display textboxes inside and they will have access to the bound data.

I have attached a sample report with this approach, please check it out.

 

Roman
Top achievements
Rank 1
Iron
commented on 25 Apr 2023, 02:58 PM

Hi Dimitar

Once again, thank you so much. Works like a charm :) I set the binding at the wrong place. After fixing this, the report is displayed properly.

Thanks & Best Regards,
Roman

Andrew
Top achievements
Rank 1
commented on 16 Jun 2023, 09:24 PM

@dimitar,

Can you comment on launching the designer with the --roll-forward switch? I also have a .net7 class that I'm trying to feed into an object data source.

I'm trying to run it with this argument: --roll-forward LatestMajor

But it keeps throwing this exception:

 

Thanks,

Andrew

Dimitar
Telerik team
commented on 20 Jun 2023, 12:09 PM

Hello Andrew,

This is a known problem that appeared with the latest version of the product - Telerik Reporting - Progress® Telerik® Reporting R2 2023 (17.1.23.606).

The issue has been fixed internally and will be available in the next service pack release. Until then, please use the older version of the designer - Telerik Reporting - Progress® Telerik® Reporting R1 2023 SP1 (17.0.23.315), or have your assemblies additionally built for .NET 6. You can still build them for .NET 7 for your project as that is only an issue with the designer.

Please accept our apologies for the caused inconvenience.

Andrew
Top achievements
Rank 1
commented on 20 Jun 2023, 01:01 PM

Thanks Dimitar!, We'll do.
Tags
DataSource Object DataSources Report Parameters Report Viewer - Blazor
Asked by
Roman
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Share this question
or