Skip to content

Commit 4967187

Browse files
committed
[aspnet reporting] Added report picker to the HTML5 ReportViewer demo page
1 parent ba2a6be commit 4967187

9 files changed

Lines changed: 51 additions & 5 deletions

File tree

src/AspNetCore/MyAspNetCoreApp/Controllers/HomeController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace MyAspNetCoreApp.Controllers;
66

7-
public class HomeController(ILogger<HomeController> logger) : Controller
7+
public class HomeController(ILogger<HomeController> logger, IWebHostEnvironment environment) : Controller
88
{
99
public IActionResult Index()
1010
{
@@ -13,13 +13,23 @@ public IActionResult Index()
1313

1414
public IActionResult ReportViewer()
1515
{
16+
var reportsPath = Path.Combine(environment.ContentRootPath, "Reports");
17+
18+
var reports = Directory.GetFiles(reportsPath, "*.trdp")
19+
.Select(Path.GetFileName)
20+
.OrderBy(n => n)
21+
.ToList();
22+
23+
ViewBag.Reports = reports;
24+
1625
return View();
1726
}
1827

1928
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
2029
public IActionResult Error()
2130
{
2231
logger.LogError($"An error occurred while processing the request. {Activity.Current?.Id ?? HttpContext.TraceIdentifier}");
32+
2333
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
2434
}
2535
}
451 KB
Binary file not shown.
Binary file not shown.
253 KB
Binary file not shown.
951 KB
Binary file not shown.
172 KB
Binary file not shown.
615 Bytes
Binary file not shown.
701 KB
Binary file not shown.

src/AspNetCore/MyAspNetCoreApp/Views/Home/ReportViewer.cshtml

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,42 @@
11
<style type="text/css">
2+
#reportPicker-wrapper {
3+
display: flex;
4+
align-items: center;
5+
justify-content: flex-start;
6+
padding: 5px;
7+
font-family: Verdana, Arial;
8+
}
9+
#reportPicker-wrapper .k-combobox {
10+
width: 300px;
11+
}
212
#reportViewer1 {
313
position: absolute;
414
left: 5px;
515
right: 5px;
6-
top: 50px;
7-
bottom: 5px;
16+
top: 120px;
17+
bottom: 65px;
818
overflow: hidden;
919
font-family: Verdana, Arial;
1020
}
1121
</style>
1222

23+
<!-- Hidden UI for ASP.NET Core component workaround for Kendo jQuery license validation fails (ReportViewer uses the components).
24+
<kendo-button name="license-workaround"></kendo-button>-->
25+
26+
<div id="reportPicker-wrapper">
27+
<kendo-combobox name="reportPicker"
28+
placeholder="Choose a report..."
29+
suggest="true"
30+
bind-to="(IEnumerable<string>)ViewBag.Reports"
31+
on-change="onReportSelected">
32+
</kendo-combobox>
33+
</div>
34+
1335
<div id="reportViewer1">
1436
loading report viewer...
1537
</div>
1638

17-
<!-- Hidden UI for ASP.NET Core component workaround for Kendo jQuery license validation fails (ReportViewer uses the components). -->
18-
<kendo-button name="license-workaround"></kendo-button>
39+
1940

2041
<script>
2142
$(document).ready(function () {
@@ -30,5 +51,20 @@
3051
enableAccessibility: false,
3152
sendEmail: { enabled: false }
3253
});
54+
55+
// Pre-select the default report in the combobox
56+
var comboBox = $("#reportPicker").data("kendoComboBox");
57+
58+
if (comboBox) {
59+
comboBox.value("Barcodes Report.trdp");
60+
}
3361
});
62+
63+
function onReportSelected(e) {
64+
var selectedReport = e.sender.value();
65+
if (selectedReport) {
66+
var reportViewer = $("#reportViewer1").data("telerik_ReportViewer");
67+
reportViewer.reportSource({ report: selectedReport });
68+
}
69+
}
3470
</script>

0 commit comments

Comments
 (0)