Skip to main content
A newer version of this page is available. .

DrillThroughContext Class

Contains information about drill-through navigation.

Namespace: DevExpress.XtraReports.Web.WebDocumentViewer

Assembly: DevExpress.XtraReports.v20.2.Web.dll

NuGet Package: DevExpress.Web.Reporting.Common

Declaration

public class DrillThroughContext

Remarks

You can click on the report data displayed in the Document Viewer or Report Designer Preview to show another report with related data (drill-through).

To implement drill-through navigation, do the following:

ASP.NET MVC

Create a class with the IWebDocumentViewerDrillThroughProcessor interface. The IWebDocumentViewerDrillThroughProcessor.CreateReport method accepts the DrillThroughContext object and returns a report for display. Call the DefaultWebDocumentViewerContainer.RegisterWebDocumentViewerDrillThroughProcessor<T> method to register a custom drill-through processor at application startup.

using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.WebDocumentViewer;
using WebApplication1.Reports;
// ...
  public class CustomDrillThroughProcessor : IWebDocumentViewerDrillThroughProcessor {
      public XtraReport CreateReport(DrillThroughContext context) {
          if (context.CustomData == "#back")
              return new MainReport();
          if (context.CustomData == "#detail1")
              return new DetailReport1();
          if (context.CustomData == "#detail2")
              return new DetailReport2();
          return context.Report;
      }
  }

To get data related to the clicked element, handle the client-side PreviewClick event:

<html>
<head runat="server">
   <script>
       function previewClick(s, e) {
           var brick = e.Brick;
           var previewModel = s.GetPreviewModel();
           var reportPreview = previewModel && previewModel.reportPreview;
           if (brick && brick.navigation && brick.navigation.url && ["#back", "#detail1", "#detail2"].indexOf(brick.navigation.url) >= 0) {
               reportPreview.drillThrough(brick.navigation.url);
               e.Handled = true;
           }
       }
   </script>
</head>
<body>
   <form id="form1" runat="server">
   <div>    
       <dx:ASPxWebDocumentViewer ID="ASPxWebDocumentViewer1" runat="server">
           <ClientSideEvents PreviewClick="previewClick"/>
       </dx:ASPxWebDocumentViewer>    
   </div>
   </form>
</body>
</html>

View Example: How to provide drill-through functionality to web reports

ASP.NET Core

Create a class with the IDrillThroughProcessor interface. The IDrillThroughProcessor.CreateReport method accepts the DrillThroughContext object and returns a report for display. Call the ServiceCollectionServiceExtensions.AddScoped<TService,TImplementation> method to register a custom drill-through processor at application startup.

You can asynchronously create reports for drill-through navigation with the IDrillThroughProcessorAsync interface implementation. It contains the CreateReportAsync method. At application startup you should call the ReportingConfigurationBuilder.UseAsyncEngine method and register a custom service with the ServiceCollectionServiceExtensions.AddScoped<TService,TImplementation> method:

using System;
using System.Text.Json;
using System.Threading.Tasks;
using DevExpress.XtraReports.Services;
using DevExpress.XtraReports.Web.WebDocumentViewer;
// ...
    public class NavigateInfo {
        public string NavigateTo { get; set; }
        public string MasterID { get; set; }
    }
    public class CustomDrillThroughProcessorAsync : IDrillThroughProcessorAsync {
        readonly IReportProviderAsync reportProviderAsync;

        public CustomDrillThroughProcessorAsync(IReportProviderAsync reportProviderAsync) {
            this.reportProviderAsync = reportProviderAsync;
        }
        public async Task<DrillThroughResult> CreateReportAsync(DrillThroughContext context) {
            NavigateInfo navigateInfo = JsonSerializer.Deserialize<NavigateInfo>(context.CustomData);
            var reportNameToOpen = navigateInfo.NavigateTo == "back" ? "MainReport"
                : navigateInfo.NavigateTo == "details" ? "DetailReport1" : null;
            var report = await reportProviderAsync.GetReportAsync(reportNameToOpen, null) ?? context.Report;

            if(navigateInfo.NavigateTo == "details") {
                int catID = 0;
                Int32.TryParse(navigateInfo.MasterID, out catID);
                report.Parameters["categoryID"].Value = catID;
            }
            return new DrillThroughResult(report);
        }
    }

To get data related to the clicked element, handle the client-side PreviewClick event:

@model DevExpress.XtraReports.Web.WebDocumentViewer.WebDocumentViewerModel;
<script>
   function previewClick(s, e) {
       var brick = e.Brick;
       var navigationUrl = brick && brick.navigation && brick.navigation.url;
       if(navigationUrl && ["back", "details"].indexOf(navigationUrl) >= 0) {
           var reportPreview = s.GetReportPreview();
           var navigateInfo = {
               NavigateTo: navigationUrl,
               MasterID: e.GetBrickValue(),
           };
           reportPreview.drillThrough(JSON.stringify(navigateInfo));
           e.Handled = true;
       }
   }
</script>
@{
   var viewerRender = Html.DevExpress().WebDocumentViewer("DocumentViewer")
       .Height("800px")
       .ClientSideEvents(configure => configure.PreviewClick("previewClick"))
       .Bind(Model);
   @viewerRender.RenderHtml()
}

View Example: How to provide drill-through functionality to web reports

Inheritance

See Also