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

How to assign datasets to the subreport in "reportLoaded" event

Thread ID:

Created:

Updated:

Platform:

Replies:

146270 Jul 29,2019 10:21 AM UTC Jul 29,2019 02:28 PM UTC Report Platform 3
loading
Tags: Report Viewer
Martin Jørgensen
Asked On July 29, 2019 10:21 AM UTC

Hi,

I am using the Report Viewer in the following way:


    $(function () {

      var reportServiceUrl = 'http://10.0.1.221:8085/api/ReportViewer';
      
      var reportPath = 'Report.rdl';

      var setupObject =
        {
          reportServerUrl: null,
          reportServiceUrl: reportServiceUrl,
          processingMode: ej.ReportViewer.ProcessingMode.Local,
          reportPath: reportPath,
          locale: 'en-US',
          pageSettings:
          {
            paperSize: ej.ReportViewer.PaperSize.A4,
            orientation: ej.ReportViewer.Orientation.Portrait
          },
          reportLoaded: 'onReportLoaded',
          reportError: 'onReportError'
        };

      $("#container").ejReportViewer(setupObject);
    });

    function onReportError(senderobj) {
      alert("onReportError: " + senderobj);
    }

    function onReportLoaded(senderobj) {
      // alert("onReportLoaded: " + senderobj);

      var Period =
      [
        {
          "StartDate": "2018-01-01T00:00:00", "EndDate": "2019-01-02T00:00:00"
        }
      ];

      var dataObject =
      [
        {
          name: "Period",
          value: ej.DataManager(Period).executeLocal(ej.Query())
        }
      ];

      var reportObj = $('#container').data("ejReportViewer");

      reportObj.model.dataSources = dataObject;
    }



The "Report.rdl" is using embedded data.
The "Report.rdl" also uses a subreport "SubReport.rdl" using the exact same embedded dataset.

As soon as the subreport includes any defined (embedded) datasets, the report fails.

I expect, that the subreport datasources is not set, like in the code "reportObj.model.dataSources = dataObject;" for the report.

How can I assign the same dataset to the subreport?

I want to do it in the browser, and not using the:

public void OnReportLoaded(ReportViewerOptions reportOption)

in MVC.

Please help :-)

Attachment: Report_ada730c1.zip

Vinoth Srinivasan [Syncfusion]
Replied On July 29, 2019 11:03 AM UTC

Hi Martin, 
 
Please find the below code snippet for how to pass the datasource for Subreport in “Local” proceesing mode for ReportViewer. 
 
        public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
            if (reportOption.SubReportModel != null) 
            { 
                reportOption.SubReportModel.DataSources = new ReportDataSourceCollection(); 
                //reportOption.SubReportModel.DataSources.Add(new ReportDataSource { Name = "<Dataset Name>", Value = <Data collection> }); 
                reportOption.SubReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet1", Value = SubReport.GetData() }); 
            } 
        } 
 
 
If you want to filter the data based on parameter, then please find the below code snippet for your reference. 
 
public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
            if (reportOption.SubReportModel != null) 
            { 
                var parameters = new List<Syncfusion.Report.ReportParameter>(); 
                Syncfusion.Report.ReportParameter reportParameter = new Syncfusion.Report.ReportParameter(); 
                reportParameter.Name = "InvoiceID"; 
               reportParameter.Values.Add("10253"); 
                reportParameter.Labels.Add("10253"); 
                parameters.Add(reportParameter); 
 
                if (parameters != null && parameters.Count > 0) 
                { 
                    reportOption.SubReportModel.DataSources = new ReportDataSourceCollection(); 
                    reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData(Convert.ToInt32(parameters[0].Values[0])) }); 
               } 
 
            } 
        } 
 
 
Regards, 
Vinoth S. 


Martin Jørgensen
Replied On July 29, 2019 11:19 AM UTC

Hi,

The dataset is set in the client on the "reportLoaded" event.
So I do not have the data available on the MVC service.

The "reportLoaded" event sets the data like:


var Period = 
      [
        {
          "StartDate": "2018-01-01T00:00:00", "EndDate": "2019-01-02T00:00:00"
        }
      ];

      var dataObject =
      [
        {
          name: "Period",
          value: ej.DataManager(Period).executeLocal(ej.Query())
        }
      ];

      var reportObj = $('#container').data("ejReportViewer");

      reportObj.model.dataSources = dataObject;



I want the same data to be assigned to the subreport.

I have tried to do the following on MVC:

reportOption.SubReportModel.DataSources = reportOption.ReportModel.DataSources;

But it does not work. Perhaps due to the fact, that the "ReportModel.DataSources" is first set on the javascript event "reportLoaded".

Any suggestion on assigning the dataset to the subreport? (not having the data in the MVC service...)

BR Martin




Vinoth Srinivasan [Syncfusion]
Replied On July 29, 2019 02:28 PM UTC

Hi Martin, 

Currently, we don’t have an option to get the datasource details which has been set at client side in our ReportViewer. We have logged a feature request on this, and it will be implemented in any of our upcoming releases. You can keep track the feature from below feedback portal system. 


If you have any more specification/precise replication procedure or a scenario to be tested, you can add it as a comment in the portal. However, we are recommending you to pass datasource from server side. 

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