Ticket T1284202
Visible to All Users

Display 0 instead of blank in the pivotgrid export

created 4 days ago (modified 3 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

Comments (1)
E E
Evgeny (DevExpress Support) 3 days ago

    Hello,

    I don't quite get the idea behind the code, because you are trying to explicitly cast printControl.Value to the XRPivotGrid. Previously you created a container variable that is of the PrintableComponentContainer type, so this is confusing. And I assume this is confusing for C# as well. Can you explain in more detail what you're trying to do with the C# code, so I can better understand the issue?

    Regards,
    Evgeny

    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.