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. Image for the cookie policy date
close icon
If you became a customer of the Syncfusion Reporting Platform or the Report Viewer, Report Designer, or Report Writer components before October 2019 and have questions related to those products, you can request support through our forum system. However, please note that this support system is only for existing customers who are still using the Syncfusion Reporting Platform or its components and not for new customers looking for reporting products from Syncfusion.

For new customers or those with general reporting questions, we recommend contacting our support team at https://support.boldreports.com/, which is a separate brand created by Syncfusion for its reporting solutions. Our team will be happy to assist you with any questions you may have.

Thank you for choosing Syncfusion for your reporting needs.

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

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

3 Replies

VS Vinoth Srinivasan Syncfusion Team 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. 



MJ Martin Jørgensen 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





VS Vinoth Srinivasan Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon