Hi,
I have two projects; a website and a web api. (.net Core 2.0 )
The website has the following html;
$("#reportViewer1")
.telerik_ReportViewer({
//serviceUrl: "/api/reports/",
serviceUrl: "@ViewBag.TelerikReportServerUrl",
reportSource: {
report: "TelerikReportService.Report, TelerikReportService",
//report: "Barcodes Report.trdp",
parameters: {}
},
viewMode: telerikReportViewer.ViewModes.INTERACTIVE,
scaleMode: telerikReportViewer.ScaleModes.SPECIFIC,
scale: 1.0,
});
And within the web API project I have been trying to create an example Report Class file that can be served up to the client.
This is how far I have got, but it wont work and I cannot find an example of this anywhere in the forums.
("Barcodes Report.trdp" works fine, just a CODED report class, I cannot get to work)
I get the error;
"Unable to get report parameters.
An error has occurred.
Invalid report type"
CODED report class:
namespace TelerikReportService
{
public partial class SchemeReport : Telerik.Reporting.Report
{
public SchemeReport()
{
}
public DataTable GetData()
{
dynamic table = new DataTable();
table.Columns.Add("col1", typeof(int));
table.Columns.Add("col2", typeof(int));
table.Rows.Add(1, 3);
table.Rows.Add(4, 6);
table.Rows.Add(2, 5);
table.Rows.Add(4, 7);
return table;
}
public Telerik.Reporting.Report GenerateReport()
{
//create a blank report
Telerik.Reporting.Report report = new Telerik.Reporting.Report();
report.Name = "Report1";
report.PageSettings.Margins = new Telerik.Reporting.Drawing.MarginsU(Telerik.Reporting.Drawing.Unit.Inch(1.0), Telerik.Reporting.Drawing.Unit.Inch(1.0), Telerik.Reporting.Drawing.Unit.Inch(1.0), Telerik.Reporting.Drawing.Unit.Inch(1.0));
report.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Letter;
report.Width = Telerik.Reporting.Drawing.Unit.Inch(6.0);
//create a detail section and add it to the report instance's Items collection
Telerik.Reporting.DetailSection detailSection = new Telerik.Reporting.DetailSection();
detailSection.Height = Telerik.Reporting.Drawing.Unit.Inch(1);
detailSection.Name = "DetailSection";
report.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { detailSection });
//create a blank Table item
Telerik.Reporting.Table table1 = new Telerik.Reporting.Table();
table1.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.0), Telerik.Reporting.Drawing.Unit.Inch(0.0));
table1.Name = "Table1";
table1.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(4), Telerik.Reporting.Drawing.Unit.Inch(1));
//get the data for the table
dynamic data = GetData();
table1.DataSource = data;
//create a dynamic row group
Telerik.Reporting.TableGroup DetailRowGroup = new Telerik.Reporting.TableGroup();
DetailRowGroup.Groupings.Add(new Telerik.Reporting.Grouping(null));
DetailRowGroup.Name = "DetailRowGroup";
table1.RowGroups.Add(DetailRowGroup);
//add a row container
table1.Body.Rows.Add(new Telerik.Reporting.TableBodyRow(Telerik.Reporting.Drawing.Unit.Inch(0.5)));
//add columns
for (int i = 0; i <= data.Columns.Count - 1; i++)
{
//add a column container
table1.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Telerik.Reporting.Drawing.Unit.Inch(2)));
//add a static column group per data field
Telerik.Reporting.TableGroup columnGroup = new Telerik.Reporting.TableGroup();
table1.ColumnGroups.Add(columnGroup);
//header textbox
Telerik.Reporting.TextBox headerTextBox = new Telerik.Reporting.TextBox();
headerTextBox.Name = "headerTextBox" + i.ToString();
headerTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(2), Telerik.Reporting.Drawing.Unit.Inch(0.5));
headerTextBox.Value = data.Columns[i].ColumnName;
columnGroup.ReportItem = headerTextBox;
//field that will be displayed
Telerik.Reporting.TextBox detailRowTextBox = new Telerik.Reporting.TextBox();
detailRowTextBox.Name = "detailRowTextBox" + i.ToString();
detailRowTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(2), Telerik.Reporting.Drawing.Unit.Inch(0.5));
detailRowTextBox.Value = "= Fields.[" + data.Columns[i].ColumnName + "]";
table1.Body.SetCellContent(0, i, detailRowTextBox);
//add the nested items in the Table.Items collection
table1.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
headerTextBox,
detailRowTextBox
});
}
//add total group - static group out of the detail row group
table1.Body.Rows.Add(new Telerik.Reporting.TableBodyRow(Telerik.Reporting.Drawing.Unit.Inch(0.5)));
Telerik.Reporting.TableGroup totalRowGroup = new Telerik.Reporting.TableGroup();
totalRowGroup.Name = "totalRowGroup";
table1.RowGroups.Add(totalRowGroup);
for (int i = 0; i <= data.Columns.Count - 1; i++)
{
Telerik.Reporting.TextBox totalRowTextBox = new Telerik.Reporting.TextBox();
totalRowTextBox.Name = "detailRowTextBox" + i.ToString();
totalRowTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(2), Telerik.Reporting.Drawing.Unit.Inch(0.5));
totalRowTextBox.Value = "= Sum(Fields.[" + data.Columns[i].ColumnName + "])";
totalRowTextBox.Style.BackgroundColor = Color.Azure;
table1.Body.SetCellContent(1, i, totalRowTextBox);
}
//add the table in the detail section's Items collection
detailSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] { table1 });
return report;
}
}
}