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:
JavaScriptcustomizeWidgets(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
Hello,
I don't quite get the idea behind the code, because you are trying to explicitly cast
printControl.Value
to theXRPivotGrid
. Previously you created a container variable that is of thePrintableComponentContainer
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