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

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 06:03 AM

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 06:19 AM

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 09:28 AM

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