Change Datasource on Telerik Reporting HTML5 Report Viewer Net Core 6

1 Answer 275 Views
.NET Core Report Designer (standalone) Report Viewer - HTML5
Mozart
Top achievements
Rank 1
Iron
Veteran
Mozart asked on 06 Jul 2023, 06:34 AM

Hello,

How do we change the datasource of Telerik reporting dynamically using Business Object ?

I'm playing with Sample CSharp.Net6.HtmlIntegration from R1 2023 Telerik Reporting 

Here's my code :

(Reporting.cshtml)

@{
    string report = ViewBag.Report + ".trdp";
}
    
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Telerik HTML5 Report Viewer Demo</title>

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

    <link href="https://kendo.cdn.telerik.com/2022.3.913/styles/kendo.common.min.css" rel="stylesheet" id="common-css" />
    <link href="https://kendo.cdn.telerik.com/2022.3.913/styles/kendo.blueopal.min.css" rel="stylesheet" id="skin-css" />

    <script src="/Scripts/themeSwitcher.js"></script>

    <script src="/api/reports/resources/js/telerikReportViewer"></script>

    <style>
        body {
            font-family: Verdana, Arial, sans-serif;
            margin: 5px;
        }

        #reportViewer1 {
            position: absolute;
            left: 5px;
            right: 5px;
            top: 40px;
            bottom: 5px;
            overflow: hidden;
            clear: both;
        }

        #theme-switcher {
            float: right;
            width: 12em;
            height: 30px;
        }
    </style>
</head>
<body>
    <select id="theme-switcher"></select>

    <div id="reportViewer1">
        loading...
    </div>

    <script type="text/javascript">

        $(document).ready(function () {
            //Theme switcher
            themeSwitcher(
                '#theme-switcher',
                '#common-css',
                '#skin-css');

            $("#reportViewer1")
                .telerik_ReportViewer({
                    serviceUrl: "api/reports/",
                    reportSource: {
                        report: "@report",
                    },

                    viewMode: telerikReportViewer.ViewModes.INTERACTIVE,

                    scaleMode: telerikReportViewer.ScaleModes.SPECIFIC,

                    scale: 1.0,

                    enableAccessibility: false,

                    //If set to true shows the Send Mail Message toolbar button
                    sendEmail: { enabled: true }
                });
        });
    </script>

</body>
</html>

 

(ReportingController.cs)


using Microsoft.AspNetCore.Mvc;

namespace CSharp.Net6.Html5IntegrationDemo.Controllers
{
    public class ReportingController : Controller
    {
        [Route("reporting")]
        public IActionResult Index(string report)
        {

            ViewBag.Report = report;
            return View("Reporting");
        }
    }
}

 

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 10 Jul 2023, 01:48 PM

Hello, Mozart

To set a report DataSource programmatically, you need to implement Custom ReportSource Resolver(you can check Steps for Implementing a Custom ReportSource Resolver telerik documentation article for step by step guide on how to do it) in which you can Unpackage a predefined .TRDP report definition and change your report properties programmatically.

You can also have a look at Using Custom ReportSource Resolver and Custom ReportDocument Resolver - Telerik Reporting to see how to assign DataSource specifically to instantiated objects. 

Regards, Nikolay Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
Tags
.NET Core Report Designer (standalone) Report Viewer - HTML5
Asked by
Mozart
Top achievements
Rank 1
Iron
Veteran
Answers by
Nikolay
Telerik team
Share this question
or