|
| 1 | +# DevExpress Reporting |
| 2 | + |
| 3 | +In this document, we will implement [DevExpress Reporting](https://www.devexpress.com/subscriptions/reporting/) to ASP.NET Zero (ASP.NET Core version) step by step. |
| 4 | + |
| 5 | +1. Download DevExpress Reporting. |
| 6 | + |
| 7 | +2. Open your ASP.NET Zero project |
| 8 | + |
| 9 | +3. Import `DevExpress.AspNetCore.Reporting` package to `[YOURAPPNAME].Web.Mvc` project. |
| 10 | + |
| 11 | +4. Then go to `Startup.cs` and add these code parts: |
| 12 | + |
| 13 | +```csharp |
| 14 | +public IServiceProvider ConfigureServices(IServiceCollection services) |
| 15 | +{ |
| 16 | + //... |
| 17 | + services.AddDevExpressControls(); //add that |
| 18 | +} |
| 19 | + |
| 20 | +public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) |
| 21 | +{ |
| 22 | + //... |
| 23 | + app.UseDevExpressControls(); //add that |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +5. Now, We can create a sample report to test if it all works. Go to `[YOURAPPNAME].Web.Mvc` and create a folder named `Reports`. |
| 30 | +6. Right click on the `Reports` folder then click `Add` -> `New Item`, then select `DevExpress Report` item. |
| 31 | +7. Select `Blank` report in the opening wizard, and create new empty report named SampleReport. |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +*(Design your report as you wish)* |
| 36 | + |
| 37 | +8. Go to `package.json` and add following dependencies. (It is located in `[YOURAPPNAME].Web.Mvc` project) |
| 38 | + |
| 39 | + ```json |
| 40 | + dependencies: [ |
| 41 | + "devextreme": "20.2.5", |
| 42 | + "@devexpress/analytics-core": "20.2.5", |
| 43 | + "devexpress-reporting": "20.2.5", |
| 44 | + "jquery-ui-dist": "1.12.1" |
| 45 | + ] |
| 46 | + ``` |
| 47 | + |
| 48 | + *Note: Version of the nuget and npm packages should match* |
| 49 | + |
| 50 | +  |
| 51 | + |
| 52 | +9. Go to `bundles.json` in mvc project and add following bundles. |
| 53 | + |
| 54 | + ```json |
| 55 | + { |
| 56 | + "scripts": [ |
| 57 | + { |
| 58 | + "output": "view-resources/Areas/App/Views/_Bundles/sample-report-min.js", |
| 59 | + "input": [ |
| 60 | + "node_modules/jquery-ui-dist/jquery-ui.js", |
| 61 | + "node_modules/knockout/build/output/knockout-latest.js", |
| 62 | + "node_modules/devextreme/dist/js/dx.all.js", |
| 63 | + "node_modules/@devexpress/analytics-core/dist/js/dx-analytics-core.js", |
| 64 | + "node_modules/devexpress-reporting/dist/js/dx-webdocumentviewer.js" |
| 65 | + ] |
| 66 | + } |
| 67 | + ], |
| 68 | + "styles": [ |
| 69 | + { |
| 70 | + "output": "/view-resources/Areas/App/Views/_Bundles/sample-report.min.css", |
| 71 | + "input": [ |
| 72 | + "node_modules/jquery-ui-dist/jquery-ui.css", |
| 73 | + "node_modules/devextreme/dist/css/dx.common.css", |
| 74 | + "node_modules/devextreme/dist/css/dx.light.css", |
| 75 | + "node_modules/@devexpress/analytics-core/dist/css/dx-analytics.common.css", |
| 76 | + "node_modules/@devexpress/analytics-core/dist/css/dx-analytics.light.css", |
| 77 | + "node_modules/devexpress-reporting/dist/css/dx-webdocumentviewer.css" |
| 78 | + ] |
| 79 | + } |
| 80 | + ] |
| 81 | + } |
| 82 | + ``` |
| 83 | + |
| 84 | +10. Go to `_Layout.cshtml` located in `[YOURAPPNAME].Web.Mvc\Areas\App\Views\Layout\_Layout.cshtml` and add new render section named `HeaderScripts` as nonrequired. |
| 85 | + |
| 86 | +  |
| 87 | + |
| 88 | +11. Create new controller named `SampleReportController` in mvc project's Areas/App folder. |
| 89 | + |
| 90 | + ```csharp |
| 91 | + [Area("App")] |
| 92 | + public class SampleReportController : Zerov1002CoreMvcDemoControllerBase |
| 93 | + { |
| 94 | + public IActionResult Index() |
| 95 | + { |
| 96 | + return View(); |
| 97 | + } |
| 98 | + } |
| 99 | + ``` |
| 100 | + |
| 101 | +12. Create `Index.cshtml` and add following code into it. |
| 102 | + |
| 103 | + ```cshtml |
| 104 | + @using DevExpress.AspNetCore |
| 105 | + @using Zerov1002CoreMvcDemo.Web.Reports; |
| 106 | + |
| 107 | + @section Styles |
| 108 | + { |
| 109 | + <link rel="stylesheet" abp-href="/view-resources/Areas/App/Views/_Bundles/sample-report.css" asp-append-version="true" /> |
| 110 | + } |
| 111 | + |
| 112 | + @section HeaderScripts |
| 113 | + { |
| 114 | + <script abp-src="/view-resources/Areas/App/Views/_Bundles/app-layout-libs.js" asp-append-version="true"></script> |
| 115 | + |
| 116 | + <script abp-src="/view-resources/Areas/App/Views/_Bundles/sample-report.js" asp-append-version="true"></script> |
| 117 | + } |
| 118 | + |
| 119 | + <div class="content d-flex flex-column flex-column-fluid"> |
| 120 | + <abp-page-subheader title="@L("SampleReport")"> |
| 121 | + </abp-page-subheader> |
| 122 | + |
| 123 | + <div class="@(await GetContainerClass())"> |
| 124 | + <div class="card card-custom gutter-b"> |
| 125 | + <div class="card-body"> |
| 126 | + @(Html.DevExpress().WebDocumentViewer("DocumentViewer") |
| 127 | + .Height("1000px") |
| 128 | + .Bind(new SampleReport()) |
| 129 | + ) |
| 130 | + </div> |
| 131 | + </div> |
| 132 | + </div> |
| 133 | + </div> |
| 134 | + ``` |
| 135 | + |
| 136 | +Your reporting file is ready to use. |
| 137 | + |
| 138 | +Note: If you get reference error about `WebDocumentViewerController`, `QueryBuilderController` or `ReportDesignerController`, you can follow that solution. |
| 139 | + |
| 140 | +* Go to you `[YOURAPPNAME]WebMvcModule` . |
| 141 | + |
| 142 | +* Add following code into `PreInitialize` function |
| 143 | + |
| 144 | + ```csharp |
| 145 | + public override void PreInitialize() |
| 146 | + { |
| 147 | + //... |
| 148 | + IocManager.Register(typeof(WebDocumentViewerController), DependencyLifeStyle.Transient); |
| 149 | + IocManager.Register(typeof(QueryBuilderController), DependencyLifeStyle.Transient); |
| 150 | + IocManager.Register(typeof(ReportDesignerController), DependencyLifeStyle.Transient); |
| 151 | + } |
| 152 | + ``` |
| 153 | + |
| 154 | + |
0 commit comments