This is a migrated thread and some comments may be shown as answers.

Report Parmeter woes

11 Answers 458 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
Ed asked on 19 Nov 2020, 09:48 AM

Hi,

I'm having a heck of a time.  I have a trdp created with the stand alone designer.

I am NOT using the UI for parameters from the trdp(i.e. When you open the report in the report designer, all the report params are set visable = false.

The report works great when it initially loads. After the first rendering, I, though my own ui above the report, can change parameters and hit a button to refresh the report. However, none of the new parameter values are being reflect in the report.  I've tried in vane to catch the NeedDataSource event. 

There must be some secret sauce I am not pouring on my code. 

Bottom line, I would surely like an example that shows how to pass single parameters was well as and perhaps more importantly multivalue parms.

There's a lot of stuff on the net talking about passing parms,  but very little that are Blazor centric.

Please let me know if I need to explain anything further.

In the meantime, I'll go back to pulling my hair out

I've attached the razor, razor.cs and trdp files.

I working on a Blazer Server environment.

Thanks … Ed

.

 

11 Answers, 1 is accepted

Sort by
0
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 19 Nov 2020, 09:49 AM
It didn't take my uploads. How can I get these to you?
0
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 19 Nov 2020, 02:18 PM

Ok, here's the code the hard way: first the razor then the razor.cs. I don't know how I can get you the trdp.

You will note that there is a hack in place that worked around the issue.  

Thanks again … Ed

 

 

using APN.Data;
using APN.Services;
using APN.Utilities;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Telerik.ReportViewer.Blazor;
 
namespace APN.Pages.Reports.StJoe
{
    public class FermentationPrepBase : ComponentBase
    {
 
        [Inject] APNDbContext db { get; set; }
        [Inject] AppData appData { get; set; }
 
        [Inject] NavigationManager navMan { get; set; }
        public Toaster Toaster { get; set; }
        public ParmsModel Parms { get; set; }
        public List<string> lstTanks { get; set; }
        public List<Fermentation> lstFermentations { get; set; }
        public ReportSourceOptions FermentationPrepReportSource { get; set; }
        public bool HideParms { get; set; } = false;
        public string HideParmsMarkup { get; set; }
 
        protected override void OnInitialized()
        {
            base.OnInitialized();
            LoadData();
 
        }
        private void LoadData()
        {
            lstTanks = (from a in db.Tanks
                        where a.SiteId == appData.SiteId &&
                        a.IsActive == true
                        orderby a.TankCode
                        select a.TankCode
                        ).ToList();
            lstFermentations = (from a in db.Fermentations
                                where a.SiteId == appData.SiteId && a.IsActive == true
                                orderby a.FermentationName
                                select a).ToList();
            Parms = new ParmsModel();
 
            Parms.dtStart = DateTime.Now.Date.AddMonths(-6);
            Parms.dtEnd = DateTime.Now.Date;
            Parms.lstTankCodes = lstTanks;
            Parms.lstFermentations = (from a in lstFermentations select a.FermentationId).ToList();
 
            FermentationPrepReportSource = new ReportSourceOptions()
            {
                Report = "FermentationPrep.trdp",
                Parameters = new Dictionary<string, object>
                    {
                        { "StartDate", Parms.dtStart  },
                        { "EndDate", Parms.dtEnd },
                        { "Ferms", Parms.lstFermentations },
                        { "Tanks", Parms.lstTankCodes }
                    }
            };
            StateHasChanged();
 
        }
        protected override void OnAfterRender(bool firstRender)
        {
            if (firstRender)
            {
 
 
                if (appData.RawData != null && appData.RawData is ParmsModel)
                {
                    Parms = (ParmsModel)appData.RawData;
                }
                else
                {
                    Parms = new ParmsModel();
                    Parms.dtStart = DateTime.Now.Date.AddMonths(-6);
                    Parms.dtEnd = DateTime.Now.Date;
                    Parms.lstTankCodes = lstTanks = new List<string>() { "A", "B", "C", "F", "G", "H", };
                    Parms.lstFermentations = (from a in lstFermentations select a.FermentationId).ToList();
                }
 
                FermentationPrepReportSource = new ReportSourceOptions()
                {
                    Report = "FermentationPrep.trdp",
                };
                rptViewer1.ReportSource.Parameters = new Dictionary<string, object>
                    {
                        { "StartDate", Parms.dtStart  },
                        { "EndDate", Parms.dtEnd },
                        { "Ferms", Parms.lstFermentations },
                        { "Tanks", Parms.lstTankCodes }
                    };
                StateHasChanged();
            }
 
        }
 
        public class ParmsModel
        {
            [ValidateComplexType]
            //[Required]
            public List<string> lstTankCodes { get; set; }
            [Required]
            public List<int> lstFermentations { get; set; }
            [Required]
            public DateTime dtStart { get; set; } = DateTime.Now.Date.AddMonths(-3);
            [Required]
            public DateTime dtEnd { get; set; } = DateTime.Now.Date;
 
 
        }
        public void HideParameters(bool hideEm)
        {
            HideParms = hideEm;
            if (HideParms)
                HideParmsMarkup = "none";
            else
                HideParmsMarkup = "block";
 
        }
 
        public void OnSelectAllTanks()
        {
            Parms.lstTankCodes = (from a in lstTanks select a).ToList();
        }
        public void OnSelectAllFerms()
        {
            Parms.lstFermentations = (from a in lstFermentations select a.FermentationId).ToList();
        }
 
        public async Task OnRunRpt()
        {
 
            FermentationPrepReportSource = new ReportSourceOptions()
            {
                Report = "FermentationPrep.trdp",
                Parameters = new Dictionary<string, object>
                    {
                        { "StartDate", Parms.dtStart  },
                        { "EndDate", Parms.dtEnd },
                        { "Ferms", Parms.lstFermentations },
                        { "Tanks", Parms.lstTankCodes }
                    }
            };
            await rptViewer1.ClearReportSourceAsync();
            rptViewer1.ReportSource = FermentationPrepReportSource;
 
            appData.RawData = Parms;
            navMan.NavigateTo("/Reports/StJoe/FermentationPrep", true);
 
 
 
            //await rptViewer1.RefreshReportAsync();
            //StateHasChanged();
 
        }
 
        public ReportViewer rptViewer1 { get; set; }
 
    }
}

@page "/Reports/StJoe/FermentationPrep"
@using APN.Pages.Reports.StJoe
@inherits FermentationPrepBase
@using Telerik.ReportViewer.Blazor
<style>
    .trv-report-viewer {
        width: 1300px;
        height: 700px;
    }
</style>
@attribute [Authorize(Roles = "SysAdmin")]
@inject AppData appData
<div class="container" style="width:80vw;height:80vh;">
    <EditForm Model="@Parms" OnValidSubmit="@OnRunRpt">
        <ObjectGraphDataAnnotationsValidator />
        <ValidationSummary />
        @{
            if (HideParms)
            {
                <div style="font-size:7pt;cursor:pointer" @onclick="@(() => HideParameters(false))"><strong>Show Parameters</strong></div>
            }
            else
            {
                <div style="font-size:7pt;cursor:pointer" @onclick="@(() => HideParameters(true))"><strong>Hide Parameters</strong></div>
            }
        }
        <div id="hidediv" style="display:@(HideParmsMarkup)">
            <div class="row">
                <div class="col-2">
                    <div class="k-label" style="font-size:7pt">Start Date</div>
                    <TelerikDatePicker @bind-Value="@Parms.dtStart" Width="145px"></TelerikDatePicker>
                    <ValidationMessage For="@(() => Parms.dtStart)" />
                </div>
                <div class="col-2 align-content-start">
                    <div class="k-label" style="font-size:7pt">End Date</div>
                    <TelerikDatePicker @bind-Value="@Parms.dtEnd" Width="145px"></TelerikDatePicker>
                    <ValidationMessage For="@(() => Parms.dtEnd)" />
                </div>
            </div>
            <div class="row">
                <div class="col-3">
                    <div class="k-label" style="font-size:7pt;cursor: default;">
                        Tanks   
                        <AnchorLink href="#" style="font-size:7pt; cursor:pointer;" @onclick="@OnSelectAllTanks">Select all</AnchorLink>
                    </div>
                    <TelerikMultiSelect Data="@lstTanks"
                                        @bind-Value="@Parms.lstTankCodes"
                                        TextField="TankCode" ValueField="TankCode"
                                        Placeholder="select one or more Tanks"
                                        Width="350px" ClearButton="true" />
                </div>
            </div>
            <div class="row">
                <div class="col-6">
                    <div class="form-group">
                        <div class="k-label" style="font-size:7pt;cursor: default;">
                            Fermentation   
                            <AnchorLink href="#" style="font-size:7pt; cursor:pointer;" @onclick="@OnSelectAllFerms">Select all</AnchorLink>
                        </div>
                        <TelerikMultiSelect Data="@lstFermentations"
                                            @bind-Value="@Parms.lstFermentations"
                                            TextField="FermentationName" ValueField="FermentationId"
                                            Placeholder="select one or more Fermentations"
                                            Width="50vw" ClearButton="true" />
                        <TelerikButton Class="mt-2" ButtonType="@ButtonType.Submit">Submit</TelerikButton>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-10">
                <ReportViewer ViewerId="rv1" @ref="rptViewer1"
                              ServiceUrl="/api/reports"
                              ParametersAreaVisible="false"
                              ReportSource="@FermentationPrepReportSource"
                              ScaleMode="@(ScaleMode.Specific)"
                              Scale="1.0">
                </ReportViewer>
            </div>
        </div>
    </EditForm>
</div>

0
Neli
Telerik team
answered on 24 Nov 2020, 06:38 AM

Hi Ed,

I would suggest to test the approach from Dynamically Selecting and Filtering Reports in Blazor Projects KB article. It also contains a sample project which you can use as a further reference.

You can also check Dynamically Selecting and Filtering Reports with Blazor and the Telerik ReportViewer Control blog post.

If the issue is not resolved, please consider opening a new support ticket where you can upload the project or you upload it on cloud storage service and send us the link.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.)

0
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 25 Nov 2020, 11:12 AM

Got it! I assigning  the ReportSource instead of Modifying it. Don't quite understand why a the assignment fail and the modify succeeded, but I don't care, I'm off the dime. Meantime, I still don't know how to set the connection string. The 2 articles you referred me to do not mention anything about how to set the connection string at runtime. I assume I need to catch the NeedDataSource event, but I can't seem to find ANY docs on this as it relates to Blazor.

Any help ... as always will be greatly appreciated.

Ed

 

0
Neli
Telerik team
answered on 27 Nov 2020, 08:07 AM

Hello Ed,

I am glad that the previous issue was resolved. When it comes to setting the connection string run time, the recommended approach is by using a report parameter. Please, test the suggested solution from the Change Connection String dynamically through a report parameter KB article. Because the Blazor Report Viewer is a wrapper of the HTML5 report viewer, in case, you have AvailbleValues for some of the report parameters, you can also use the approach from Action NavigateToReport does not work after updating the Connection String dynamically in a Custom Report Resolver KB article.

Let us know if you need further inforamtion.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 29 Nov 2020, 08:57 AM

Ok, there must be something I'm missing.

I'm using the report designer. In my code I have:

ReportSourceOptions rso = await rptViewer1.GetReportSourceAsync();
if (appData.PorQ == "P")
    rso.Parameters["ConnectionString"] = "Data Source = Blah, blah"; //  quality connection string
else
    rso.Parameters["ConnectionString"] = "Data Source = Blah, blah"; // production connection string

 

In my trdp I created a new report parameter and assigned it to the connection string field of the Configure data source dialog (See attached screen shot.). I am unable to connect to the db this way. This is in a blazor server environment.

Please help.

Thanks … Ed

 

0
Neli
Telerik team
answered on 30 Nov 2020, 08:05 AM

Hello Ed,

Thank you for the provided screenshot.

You will need to use the report parameter as a value for the Binding. Let me explain the approach briefly. Firstly, you need to create the report parameter as you have already done. Then, for example, if you use the SQL DataSource for a table, you need to set the binding  to that table: from the Properties grid -> Binding:
   Property pathDataSource.ConnectionString (keep in mind that it is not in the dropdown list and you should type it manually)
   Expression= Parameters.ConnectionStringParameter.Value

If the datasource is set to another data item, for example, to the report or crosstab, then the Binding should be added to that item.

I attached a sample report that demonstrates the approach. Please, take a look at it and let me know if you need further assistance.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 30 Nov 2020, 08:42 AM

Hi,

Thanks for the reply. You said:

SQL DataSource for a table, you need to set the binding  to that table: from the Properties grid -> Binding:
   Property path: DataSource.ConnectionString (keep in mind that it is not in the dropdown list and you should type it manually)

But I don't see a Properties grid -> Binding field in the properties grid. Sorry for being so dense.

 


0
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 30 Nov 2020, 08:43 AM

Disregard the last. Found it!

 

0
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 30 Nov 2020, 10:57 AM

I just don't get it. I've attached 3 more screen shots. I set the Binding Expression and Path in the first screen. In the second, I set up the report parmeter. In the third, I  set the datasource connection string. I pass the parameter from my code using :

ReportSourceOptions rso = await rptViewer1.GetReportSourceAsync();
if (appData.PorQ == "P")
    rso.Parameters["ConnectionString"] = "Data Source = Blah, blah"; //  quality connection string
else
    rso.Parameters["ConnectionString"] = "Data Source = Blah, blah"; // production connection string

 

What am I missing?

Thanks.

0
Neli
Telerik team
answered on 03 Dec 2020, 09:35 AM

Hello Ed,

Thank you for the provided screenshots. From screen354d5c113436c415192104df209b47053.jpg, I noticed that you used the value of the parameter for the ConnectionString property of the SQL DataSource which is not allowed. For that reason, please, test removing it. The usage of the report parameter should happen only in the Binding, as you correctly did for the report.

Please, test this approach and let us know if the issue is resolved.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Ed
Top achievements
Rank 1
Iron
Veteran
Iron
Neli
Telerik team
Share this question
or