Ticket T1284202
Visible to All Users

Display 0 instead of blank in the pivotgrid export

created 7 days ago (modified 6 days ago)

Hi team,

I am trying to display 0 instead of blanks in the pivotgrid of the BI dashboard. On the frontend I achieved it by using below code:

JavaScript
customizeWidgets(e) {   if (e.ItemName.indexOf('pivot') >= 0) {      var pivot = e.GetWidget();      pivot.option({        onCellPrepared: function(e) {        if (e.area == 'data' && ( e.cell.value == null || e.cell.value.trim() === ""))          {          e.cellElement.text('0');          }      }      });      pivot.repaint();    }  }

Now I want to achieve the same in the pdf and excel export. Below is the code for my customExport in C# :

C#
public class DashboardConfig {     public static void RegisterService(RouteCollection routes)     {         routes.MapDashboardRoute("api/dashboard", "DashboardDesignerNew");         DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();         ObjectDataSourceConfigurator.ConfigureDataSource(DashboardConfigurator.Default, dataSourceStorage);         DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage);         DashboardConfigurator.Default.SetConnectionStringsProvider(new DevExpress.DataAccess.Web.ConfigFileConnectionStringsProvider());         DashboardConfigurator.Default.SetDashboardStorage(new DashboardFileStorage(@"~/App\_Data/"));         DashboardConfigurator.Default.CustomExport += CustomExport;     }     private static void CustomExport(object sender, CustomExportWebEventArgs e)     {         foreach (var printControl in e.GetPrintableControls())         {            // we have customised logic for charts here if (printControl.Value is PrintableComponentContainer container)             {                 if (container.PrintableComponent is DashboardPivotGridPrinter pivotGridPrinter)                 {                     // Handle pivot grid controls                     var pivotGrid = (XRPivotGrid)printControl.Value;                 // Subscribe to the CustomCellDisplayText event                 pivotGrid.CustomCellDisplayText += (s, args) =>                 {                     if (args.Value == null || string.IsNullOrEmpty(args.Value.ToString()))                     {                         args.DisplayText = "0";                     }                 };                }             } // also tried below code  // if (printControl.Key.Contains("pivotDashboardItem"))             //{                 // Handle pivot grid controls               //  var pivotGrid = printControl as XRPivotGrid ;                 // Subscribe to the CustomCellDisplayText event               //  pivotGrid.CustomCellDisplayText += (s, args) =>                // {                //     if (args.Value == null || string.IsNullOrEmpty(args.Value.ToString()))                //     {                 //        args.DisplayText = "0";                 //    }                 //};             } } }

This code is giving the following error: Unable to cast object of type 'DevExpress.XtraReports.UI.PrintableComponentContainer' to type 'DevExpress.XtraReports.UI.XRPivotGrid

Show previous comments (1)

    I am actually trying to display 0 instead of blanks in the pivotgrid of the BI dashboard in pdf and excel export, I tried number of way but didn't achieved below is the one more code I tried.

    C#
    private static void CustomExport(object sender, CustomExportWebEventArgs e) { foreach (var printControl in e.GetPrintableControls()) { // we have customised logic for charts here if (printControl.Key.Contains("pivotDashboardItem")) { // Handle pivot grid controls var pivotGrid = printControl as XRPivotGrid ; // Subscribe to the CustomCellDisplayText event pivotGrid.CustomCellDisplayText += (s, args) => { if (args.Value == null || string.IsNullOrEmpty(args.Value.ToString())) { args.DisplayText = "0"; } }; } } }

    The above code is also not working . Can you please share insights how I can solve the above problem.

    E E
    Evgeny (DevExpress Support) 17 hours ago

      Hello,

      Could you please share more details about what exactly is "not working"? Do you see any error messages? Have you tried logging the export? For more information on how to log server side code, please see this help topic: Handle and Log Server-Side Errors in ASP.NET MVC.

      Regards,
      Evgeny

      VS VS
      VANI SREEDHAR 1 8 hours ago

        Hi

        Actually it is not able to convert the printControl into XRPivotGrid the code line
        var pivotGrid = printControl as XRPivotGrid return the null value actually it fails to cast the printControl into XRPivotGrid.

        If u still not able to understand it you can discard this code.My main concern is ensuring that blank values in the pivot grid of the BI dashboard are displayed as 0 when exporting to PDF and Excel. Could you please provide a solution for this?

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.