How to pass LightSwitchHtml application data to ReportViewer datasource
How to pass LightSwitchHtml application data to ReportViewer datasource
This article describes how to pass application data to ReportViewer datasource in LightSwitch Application. You can also refer to the Getting Started with JavaScript ReportViewer from the User Guide, available in the following link:
https://help.syncfusion.com/lightswitch/html-client/reportviewer/create-a-simple-reportviewer
Passing application data to ReportViewer:
You can get the LSHTML application data and passed to ReportViewer using the following code sample.
public class ReportAPIController : ApiController, IReportController { public object PostReportAction(Dictionary<string, object> jsonResult) { return ReportHelper.ProcessReport(jsonResult, this); } [System.Web.Http.ActionName("GetResource")] [AcceptVerbs("GET")] public object GetResource(string key, string resourcetype, bool isPrint) { return ReportHelper.GetResource(key, resourcetype, isPrint); } public void OnInitReportOptions(ReportViewerOptions reportOption) { var hostedPath = System.Web.HttpContext.Current.Server.MapPath("~/"); var rdlPath = hostedPath + "bin\\LSSSRSDemo.Server\\ReportTemplate\\" + reportOption.ReportModel.ReportPath; reportOption.ReportModel.ReportPath = rdlPath; } public void OnReportLoaded(ReportViewerOptions reportOption) { if (reportOption.ReportModel.ReportPath.Contains("TicketReport")) { reportOption.ReportModel.DataSources.Clear(); reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "ETickets", Value = GetTickets() }); } } public object GetTickets() { using (ServerApplicationContext ctx = ServerApplicationContext.CreateContext()) { var tickets = ctx.DataWorkspace.ApplicationData.TicketsSet.GetQuery() .Execute() .ToList(); return tickets; } } }
Demo Sample
You can download the Demo Sample from the following link.
Further References
You can find documentation and demo samples for JavaScript ReportViewer Control from the following link.
https://help.syncfusion.com/lightswitch/html-client/lightswitch-for-html-client