We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Dynamically refresh datasources based on user parameters

Thread ID:

Created:

Updated:

Platform:

Replies:

149151 Nov 15,2019 08:50 PM UTC Nov 25,2019 05:59 AM UTC Report Platform 5
loading
Tags: Report Viewer
Yousri Lachtar
Asked On November 15, 2019 08:50 PM UTC

Hi,

I am using a trial of bold reports (RDLC & MVC 5 application). I have a requirement to refresh the report data sources based on report parameters. I am able to initially fill the datasources and the view the report but when I change the value one of the parameters, I need to refresh the query accordingly and display the result.
Thanks for your help.

YL

Attachment: Report_879b4e64.zip

Mahendran Shanmugam [Syncfusion]
Replied On November 18, 2019 07:02 AM UTC

Hi Yousri, 

We cannot able to change the RDLC datasource when changing the parameter values in parameter dialog. But we can able to filter the data for RDLC report at programmatically as shown in below code when clicking the external button in example. 
<div style="height: 600px; width: 950px;"> 
        <label> 
            CustomerID: 
            <input type="text" name="CustomerID" id="customerid" > 
        </label> 
        <input type="button" value="Submit"  onclick="onClick()" > 
        <!-- Creating a div tag which will act as a container for boldReportViewer widget.--> 
        <div style="height: 600px; width: 950px; min-height: 400px;" id="viewer"></div> 
        <!-- Setting property and initializing boldReportViewer widget.--> 
        <script type="text/javascript"> 
            var parameters = [{ 
                name: 'CustomerID', 
                labels: ['29661'], 
                values: [29661], 
                nullable: false 
            }]; 
 
            $(function () { 
                $("#viewer").boldReportViewer({ 
                    reportServiceUrl: 'http://localhost:62611/api/ReportApi', 
                    reportPath: 'Region.rdlc', 
                    processingMode: ej.ReportViewer.ProcessingMode.Local, 
                    ajaxBeforeLoad: ajaxBeforeLoad, 
                    parameters: [{ 
                        name: 'CustomerID', 
                        labels: ['29661'], 
                        values: [29661], 
                        nullable: false 
                    }] 
                }); 
            }); 
 
            function ajaxBeforeLoad(event) { 
                event.data = parameters; 
            }; 
 
            function onClick(element) { 
                parameters = [{ 
                    name: 'CustomerID', 
                    labels: [document.getElementById("customerid").value], 
                    values: [document.getElementById("customerid").value], 
                    nullable: false 
                }]; 
                var reportviewer = $("#viewer").data('boldReportViewer'); 
                reportviewer.setModel({ "parameters": parameters }); 
            }; 
        </script> 
    </div> 
</body> 
</html> 
  
    [RoutePrefix("api/ReportApi")] 
    [EnableCors(origins: "*", headers: "*", methods: "*")] 
    public class ReportApiController : ApiController,IReportController  
    { 
        protected string reportPath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/"); 
        public string DefaultParam = null; 
        //Post action for processing the rdl/rdlc report  
        [HttpPost] 
        [Route("PostReportAction")] 
        public object PostReportAction(Dictionary < string, object > jsonResult)  
        { 
            if (jsonResult.ContainsKey("customData")) 
            { 
                DefaultParam = jsonResult["customData"].ToString(); 
            } 
 
            return ReportHelper.ProcessReport(jsonResult, this); 
        } 
         
        //Get action for getting resources from the report 
        [System.Web.Http.ActionName("GetResource")] 
        [AcceptVerbs("GET")] 
        public object GetResource(string key, string resourcetype, bool isPrint)  
        { 
            return ReportHelper.GetResource(key, resourcetype, isPrint); 
        } 
         
        //Method will be called when initialize the report options before start processing the report         
        public void OnInitReportOptions(ReportViewerOptions reportOption) 
        { 
            reportOption.ReportModel.ReportPath = reportPath + reportOption.ReportModel.ReportPath; 
            reportOption.ReportModel.DataSources.Clear(); 
        } 
 
        //Method will be called when reported is loaded 
        public void OnReportLoaded(ReportViewerOptions reportOption)  
        { 
            var parameters = new List<ReportParameter>(); 
            if (DefaultParam != null) 
            { 
                parameters = JsonConvert.DeserializeObject<List<ReportParameter>>(DefaultParam); 
            } 
 
            if (parameters != null && parameters.Count > 0) 
            { 
                reportOption.ReportModel.DataSources.Clear(); 
                reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData(Convert.ToInt32(parameters[0].Values[0])) }); 
            } 
        } 
    } 
 
Please find the below attached application for your reference. 

Regards, 
Mahendran S. 


Yousri Lachtar
Replied On November 18, 2019 02:08 PM UTC

Thanks for your reply.
Can we do the same thing without the custom button. I mean from the oob button "VIEW REPORT" ?

YL

Vinoth Srinivasan [Syncfusion]
Replied On November 19, 2019 01:25 PM UTC

Hi Yousri, 
 
Currently we don’t have option to filter the data when clicking the ViewReportClick for RDLC report. So, could you please set the filter for report items based on parameters as shown in below example. 
 
 
 
Regards, 
Vinoth S. 


Yousri Lachtar
Replied On November 23, 2019 08:16 PM UTC

Thanks for your help.

Vinoth Srinivasan [Syncfusion]
Replied On November 25, 2019 05:59 AM UTC

Hi Yousri, 

Thanks for your update. Please let us know if you require further assistance on this. 

Regards, 
Vinoth S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon