<div style="height: 600px; width: 950px;">
<label>
CustomerID:
<input type="text" name="CustomerID" id="customerid" >
</label>
<input type="button" value="Submit" onclick="onClick()" >
<!-- Creating a div tag which will act as a container for boldReportViewer widget.-->
<div style="height: 600px; width: 950px; min-height: 400px;" id="viewer"></div>
<!-- Setting property and initializing boldReportViewer widget.-->
<script type="text/javascript">
var parameters = [{
name: 'CustomerID',
labels: ['29661'],
values: [29661],
nullable: false
}];
$(function () {
$("#viewer").boldReportViewer({
reportServiceUrl: 'http://localhost:62611/api/ReportApi',
reportPath: 'Region.rdlc',
processingMode: ej.ReportViewer.ProcessingMode.Local,
ajaxBeforeLoad: ajaxBeforeLoad,
parameters: [{
name: 'CustomerID',
labels: ['29661'],
values: [29661],
nullable: false
}]
});
});
function ajaxBeforeLoad(event) {
event.data = parameters;
};
function onClick(element) {
parameters = [{
name: 'CustomerID',
labels: [document.getElementById("customerid").value],
values: [document.getElementById("customerid").value],
nullable: false
}];
var reportviewer = $("#viewer").data('boldReportViewer');
reportviewer.setModel({ "parameters": parameters });
};
</script>
</div>
</body>
</html> |
|
[RoutePrefix("api/ReportApi")]
[EnableCors(origins: "*", headers: "*", methods: "*")]
public class ReportApiController : ApiController,IReportController
{
protected string reportPath = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/");
public string DefaultParam = null;
//Post action for processing the rdl/rdlc report
[HttpPost]
[Route("PostReportAction")]
public object PostReportAction(Dictionary < string, object > jsonResult)
{
if (jsonResult.ContainsKey("customData"))
{
DefaultParam = jsonResult["customData"].ToString();
}
return ReportHelper.ProcessReport(jsonResult, this);
}
//Get action for getting resources from the report
[System.Web.Http.ActionName("GetResource")]
[AcceptVerbs("GET")]
public object GetResource(string key, string resourcetype, bool isPrint)
{
return ReportHelper.GetResource(key, resourcetype, isPrint);
}
//Method will be called when initialize the report options before start processing the report
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.ReportPath = reportPath + reportOption.ReportModel.ReportPath;
reportOption.ReportModel.DataSources.Clear();
}
//Method will be called when reported is loaded
public void OnReportLoaded(ReportViewerOptions reportOption)
{
var parameters = new List<ReportParameter>();
if (DefaultParam != null)
{
parameters = JsonConvert.DeserializeObject<List<ReportParameter>>(DefaultParam);
}
if (parameters != null && parameters.Count > 0)
{
reportOption.ReportModel.DataSources.Clear();
reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "StoreSales", Value = StoreSales.GetData(Convert.ToInt32(parameters[0].Values[0])) });
}
}
} |