The data binding support allows you view the RDLC reports that exist on the local file system with JSON array and custom business object data collection. The following steps demonstrates how to render an RDLC report with JSON array and custom business object data collection.
Add the RDLC report
AreaCharts.rdlc
from the Bold Reports installation location to your applicationApp_Data
folder. For more information, refer to Samples and demos.
To bind the data source at client side, follow these steps;
reportPath
property.processingMode
property to ProcessingMode.Local
.dataSources
property as shown in following code.var viewerStyle = {'height': '700px', 'width': '100%'};
var reportPath = 'AreaCharts.rdlc';
var reportData = [{
value: [
{ SalesPersonID: 281, FullName: 'Ito', Title: 'Sales Representative', SalesTerritory: 'South West', Y2002: 0, Y2003: 28000, Y2004: 3018725 },
{ SalesPersonID: 282, FullName: 'Saraiva', Title: 'Sales Representative', SalesTerritory: 'Canada', Y2002: 25000, Y2003: 14000, Y2004: 3189356 },
{ SalesPersonID: 283, FullName: 'Cambell', Title: 'Sales Representative', SalesTerritory: 'North West', Y2002: 12000, Y2003: 13000, Y2004: 1930885 }
],
name: 'AdventureWorksXMLDataSet'
}];
function App() {
return (
<div style={viewerStyle}>
<BoldReportViewerComponent
id="reportviewer-container"
reportServiceUrl = {'https://demos.boldreports.com/services/api/ReportViewer'}
processingMode = {"Local"}
reportPath = {reportPath}
dataSources = {reportData}>
</BoldReportViewerComponent>
</div>
);
}
export default App;
The following steps help you configure the Web API to render the RDLC report with business object data collection.
Create a class and methods that returns business object data collection. Use the following code in your application Web API Service.
public class ProductList
{
public string ProductName { get; set; }
public string OrderId { get; set; }
public double Price { get; set; }
public string Category { get; set; }
public string Ingredients { get; set; }
public string ProductImage { get; set; }
public static IList GetData()
{
List<ProductList> datas = new List<ProductList>();
ProductList data = null;
data = new ProductList()
{
ProductName = "Baked Chicken and Cheese",
OrderId = "323B60",
Price = 55,
Category = "Non-Veg",
Ingredients = "grilled chicken, corn and olives.",
ProductImage = ""
};
datas.Add(data);
data = new ProductList()
{
ProductName = "Chicken Delite",
OrderId = "323B61",
Price = 100,
Category = "Non-Veg",
Ingredients = "cheese, chicken chunks, onions & pineapple chunks.",
ProductImage = ""
};
datas.Add(data);
data = new ProductList()
{
ProductName = "Chicken Tikka",
OrderId = "323B62",
Price = 64,
Category = "Non-Veg",
Ingredients = "onions, grilled chicken, chicken salami & tomatoes.",
ProductImage = ""
};
datas.Add(data);
return datas;
}
}
Set the value of the ProcessingMode
property to ProcessingMode.Local
and ReportPath
in the RDLC report location.
Bind the business object data values collection by adding a new item to the DataSources
as shown in the following code snippet.
[NonAction]
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
reportOption.ReportModel.ProcessingMode = ProcessingMode.Local;
reportOption.ReportModel.ReportPath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/Product List.rdlc");
reportOption.ReportModel.DataSources.Add(new BoldReports.Web.ReportDataSource { Name = "list", Value = ProductList.GetData() });
}
Here the
Name
is case sensitive and it should be same as in the data source name in the report definition. TheValue
accepts IList, DataSet, and DataTable inputs.
To load report as a stream, create a report stream using the FileStream
class and assign the report stream to the Stream
property.
[NonAction]
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
string filePath = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/Product List.rdlc"); ;
// Opens the report from application App_Data folder using FileStream
FileStream reportStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
reportOption.ReportModel.Stream = reportStream;
reportOption.ReportModel.DataSources.Add(new BoldReports.Web.ReportDataSource { Name = "list", Value = ProductList.GetData() });
}
In the previous code, the
Product List.rdlc
report is loaded from theApp_Data
folder location.
You can get the user selected parameter details when users clicks the ViewReport
button in the parameter block. The viewReportClick
event allows you handle the ViewReport
button click at client side as shown in the following code.
var viewerStyle = {'height': '700px', 'width': '100%'};
var reportPath = 'GroupingAgg.rdl';
function viewReportClick(event) {
var reportParams = [];
reportParams.push({ name: 'ReportParameter1', labels: ['SO50756'], values: ['SO50756'] });
event.model.parameters = reportParams;
}
function App() {
return (
<div style={viewerStyle}>
<BoldReportViewerComponent
id="reportviewer-container"
reportServiceUrl = {'https://demos.boldreports.com/services/api/ReportViewer'}
processingMode = {"Local"}
reportPath = {reportPath}
viewReportClick = {viewReportClick}>
</BoldReportViewerComponent>
</div>
);
}
export default App;
The model property in the event argument has the details of current processing report model.