Wijmo ReportViewer with Custom Recordset

Posted by: avazquez on 24 July 2019, 4:48 pm EST

  • Posted 24 July 2019, 4:48 pm EST

    I created a Web API that implements a custom Report provider so that way Im able to set dynamic recordset on server side.

    This is my custom report provider

    
    public class ReportDataProvider : ReportProvider
        {
            public string ReportPath { get; private set; }
            public string ReportName { get; private set; }
    
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="path">The path of report</param>
            /// <param name="reportName">The name of report</param>
            public ReportDataProvider(string path, string reportName)
            {
                ReportPath = path;
                ReportName = reportName;
            }
    
            /// <summary>
            /// Gets catalog info of the specified path.
            /// </summary>
            /// <param name="providerName">The key used to register the provider.</param>
            /// <param name="path">The relative path of the folder or report.</param>
            /// <param name="recursive">Whether to return the entire tree of child items below the specified item.</param>
            /// <param name="args">The collection of HTTP query string variables.</param>
            /// <returns>A <see cref="CatalogItem"/> object.</returns>
            public override CatalogItem GetCatalogItem(string providerName, string path, bool recursive, NameValueCollection args = null)
            {
                throw new NotImplementedException();
            }
    
            /// <summary>
            /// Creates the document for the specified report path.
            /// </summary>
            /// <param name="path">The relative path of the report, without the registered key for the report provider.</param>
            /// <param name="args">The collection of HTTP query string variables.</param>
            /// <returns>A <see cref="C1DocumentSource"/> created for the specified path.</returns>
            protected override C1DocumentSource CreateDocument(string path, NameValueCollection args)
            {
                // in this sample, the path is "ReportsRoot/DataSourceInMemory.flxr/Simple List".
    
                var report = new C1FlexReport();
                report.Load(ReportPath, ReportName);
    
                UpdateDataSource(report, args);
                return report;
            }
    
            private void UpdateDataSource(C1FlexReport report, NameValueCollection args)
            {
                if (report == null || args == null) return;
    
                var dataSource = args["dataSource"];
                report.DataSourceName = dataSource;
            }
        }
    

    And in my Startup.cs I set it like this:

      app.UseReportProviders().Add("memoryreports", new ReportDataProvider(GetFullRoot("ReportsRoot") + "\\DataBinding\\Nwind.flxr", "Invoice"));
    

    What I need is that instead of passing a hardcoded report I can get the report name in my report provider.

    Right now the only way I think to do this is by parsing the path variable in:

    protected override C1DocumentSource CreateDocument(string path, NameValueCollection args)
    

    Any clue on how to get the report file and report name in the Report provider?

  • Posted 25 July 2019, 7:12 am EST

    Hi Alejandro,

    Yes, you can get the report path and report name by parsing the path variable. We believe that you must be using the CustomReportProvider sample from the MVC forum. So, we have updated the sample so that it parses the path value and return the report path and name.

    CustomReportProvider.zip

    Regards,

    Ashwin

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels