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
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.
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.
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
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?