Check the attached screenshot:
Implement Right-to-Left support for RadPivotGrid.
If you have an object with string property and for all the available objects in the RadPivotgrid you have numeric values for this property with leading zero digits (e.g. "002"), it is exported in Excel as a numeric cell.
To reproduce: Add a RadPivotGrid and a few columns, select one column and show the PrintingDialog. Select "Print Selection Only", exception will occur. Workaround: Use the following print style - public class MyPrintStyle : PivotGridPrintStyle { private Func<Rectangle, SizeF> getScaleFactors; private Func<int, Rectangle, float, int> getStartColumn; private Func<int, Rectangle, float, int> getEndColumn; private Func<int, Rectangle, float, int> getStartRow; private Func<int, Rectangle, float, int> getEndRow; private List<AggregateDescriptionBase> aggregates; private List<int> columnWidths; private List<int> rowHeights; private Type baseType; private BindingFlags flags; public override void Initialize() { base.Initialize(); this.baseType = typeof(PivotGridPrintStyle); this.flags = BindingFlags.NonPublic | BindingFlags.Instance; this.getScaleFactors = this.GetFuncFromParent<Rectangle, SizeF>("GetScaleFactors"); this.getStartColumn = this.GetFuncFromParent<int, Rectangle, float, int>("GetStartColumn"); this.getEndColumn = this.GetFuncFromParent<int, Rectangle, float, int>("GetEndColumn"); this.getStartRow = this.GetFuncFromParent<int, Rectangle, float, int>("GetStartRow"); this.getEndRow = this.GetFuncFromParent<int, Rectangle, float, int>("GetEndRow"); this.aggregates = GetField<List<AggregateDescriptionBase>>("aggregates"); this.columnWidths = GetField<List<int>>("columnWidths"); this.rowHeights = GetField<List<int>>("rowHeights"); } private T GetField<T>(string name) { return (T)this.baseType.GetField(name, flags).GetValue(this); } private Func<T, TResult> GetFuncFromParent<T, TResult>(string method) { MethodInfo getScaleFactor = baseType.GetMethod(method, flags); var func = (Func<T, TResult>)Delegate.CreateDelegate(typeof(Func<T, TResult>), this, getScaleFactor); return func; } private Func<T1, T2, T3, TResult> GetFuncFromParent<T1, T2, T3, TResult>(string method) { MethodInfo getScaleFactor = baseType.GetMethod(method, flags); var func = (Func<T1, T2, T3, TResult>)Delegate.CreateDelegate(typeof(Func<T1, T2, T3, TResult>), this, getScaleFactor); return func; } public override void DrawPage(Rectangle drawArea, Graphics graphics, int pageNumber) { int x = drawArea.X; int y = drawArea.Y; SizeF scale = this.getScaleFactors(drawArea); int startColumn = this.getStartColumn(pageNumber, drawArea, scale.Width); int endColumn = this.getEndColumn(startColumn, drawArea, scale.Width); int startRow = this.getStartRow(pageNumber, drawArea, scale.Height); int endRow = this.getEndRow(startRow, drawArea, scale.Height); int aggregateIndex = 0; for (int i = startRow; i <= endRow; i++) { x = drawArea.X; int maxHeight = 0; for (int j = startColumn; j <= endColumn; j++) { if (j == 0 && i == 0 && aggregateIndex < this.aggregates.Count) { while (aggregateIndex < this.aggregates.Count) { if (j >= this.columnWidths.Count || i >= this.rowHeights.Count) { break; } Rectangle aggregateElementRect = new Rectangle(x, y, this.columnWidths[j], this.rowHeights[i]); RadPrintElement aggregatePrintElement = this.GetAggregateDescriptorCell(aggregateIndex++); aggregatePrintElement.ScaleTransform = scale; RectangleF aggregateTransformedRect = aggregatePrintElement.GetTransformedBounds(aggregateElementRect); this.PrintElement(aggregatePrintElement, drawArea, aggregateElementRect, graphics); x += (int)Math.Floor(aggregateTransformedRect.Width); maxHeight = Math.Max(maxHeight, (int)Math.Floor(aggregateTransformedRect.Height)); if (aggregateIndex < this.aggregates.Count) { j++; } } continue; } Rectangle elementRect = new Rectangle(x, y, this.columnWidths[j], this.rowHeights[i]); RadPrintElement printElement = this.GetPrintElementForCell(i, j); printElement.ScaleTransform = scale; RectangleF transformedRect = printElement.GetTransformedBounds(elementRect); this.PrintElement(printElement, drawArea, elementRect, graphics); x += (int)Math.Floor(transformedRect.Width); maxHeight = Math.Max(maxHeight, (int)Math.Floor(transformedRect.Height)); } y += maxHeight; } } }
In this case, we have Field1 and Field2 and some of the data source items will have equal values for both properties. In this case, the equal value is an empty string.
When we filter the rows by removing the empty string value, it will also remove the column which has the same value(empty string).
The result is not correct.
When the RowGrandTotalsPosition and ColumnGrandTotalsPosition for RadPivotGrid are set to First, it would be suitable to offers options for keeping the row/column grand totals always visible in the view after scrolling:
To reproduce: Try setting the value in the CellForamting event. Workaround: class MySpreadExportRenderer : SpreadExportRenderer { public override void SetCellSelectionValue(DataType dataType, object value) { base.SetCellSelectionValue(dataType, value); if (dataType == DataType.Number) { CellRange range = ((CellSelection)this.GetCellSelection()).CellRanges.ElementAtOrDefault(0); double d; if (double.TryParse(Convert.ToString(value), out d)) { var cell = ((Worksheet)this.GetWorksheet()).Cells[range.FromIndex.RowIndex, range.FromIndex.ColumnIndex]; cell.SetFormat(new CellValueFormat("#,##0.00")); cell.SetValue(d); } } } }
How to reproduce: check the attached project and screenshots, the correct items are shown in screenshot correct-items-calculated-field.jpg Workaround: public partial class Form1 : Form { private LocalDataSourceProvider provider; public Form1() { InitializeComponent(); //Setup pivot and add calculated field //Workaround this.radPivotFieldList1.ValuesControl.CreatingVisualListItem += ValuesControl_CreatingVisualListItem; } private void ValuesControl_CreatingVisualListItem(object sender, CreatingVisualListItemEventArgs args) { args.VisualItem = new MyPivotFieldListVisualItem(this.radPivotFieldList1.ViewModel); } } public class MyPivotFieldListVisualItem : PivotFieldListVisualItem { FieldListViewModel viewModel; public MyPivotFieldListVisualItem(FieldListViewModel viewModel) : base(viewModel) { this.viewModel = viewModel; } protected override void UpdateContextMenu() { base.UpdateContextMenu(); PivotFieldListItemButton button = (PivotFieldListItemButton)typeof(PivotFieldListVisualItem).GetField("button", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this); string providerName = this.viewModel.DataProvider != null ? this.viewModel.DataProvider.GetType().FullName : String.Empty; if (this.Data == null) { return; } if (this.Data.DataBoundItem is Value && !(providerName.Contains("Xmla") || providerName.Contains("Adomd"))) { for (int i = 0; i < 5; i++) { button.Items.RemoveAt(i); } } } }
Need to have the ability to resize the height of the aggregate area along with other features that will help the user see/discern the labels properly
Request is to have the ability preferably using a mouse drag to change the height of the column headers in the grid. We can already do that for data rows of the grid, but it is not possible currently to do the same for the header row.
How to reproduce: Me.RadPivotGrid1.DataSource = Nothing Workaround: DirectCast(Me.RadPivotGrid1.DataProvider, LocalDataSourceProvider).ItemsSource = Nothing Dim viewModel = Me.RadPivotGrid1.PivotGridElement.GetType().GetField("viewModel", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(Me.RadPivotGrid1.PivotGridElement) viewModel.GetType().GetProperty("DataProvider").SetValue(viewModel, Nothing)
How to reproduce: see the attached video Workaround: public partial class Form2 : Form { public Form2() { InitializeComponent(); this.radPivotFieldList1.DragDropService = new CustomPivotFieldListDragDropService(this.radPivotFieldList1); } private void Form2_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'nwindDataSet.Orders' table. You can move, or remove it, as needed. this.ordersTableAdapter.Fill(this.nwindDataSet.Orders); } } public class CustomPivotFieldListDragDropService : PivotFieldListDragDropService { private RadPivotFieldList fieldList; private Telerik.WinControls.UI.PivotFieldList.FieldPayload payload; public CustomPivotFieldListDragDropService(RadPivotFieldList fieldList) : base(fieldList) { this.fieldList = fieldList; } protected override void PerformStart() { base.PerformStart(); Telerik.WinControls.UI.PivotFieldList.IField draggedField = this.GetField(this.Context); if (draggedField == null) { this.Stop(false); return; } this.payload = new Telerik.WinControls.UI.PivotFieldList.FieldPayload(draggedField); } protected override void OnPreviewDragOver(RadDragOverEventArgs e) { RadElement targetElement = this.DropTarget as RadElement; Telerik.WinControls.UI.PivotFieldList.IField targetField = this.GetField(targetElement); if (targetElement != null && targetElement.ElementTree.Control == this.fieldList.ReportFiltersControl && this.payload != null) { foreach (Telerik.WinControls.UI.PivotFieldList.IField field in this.fieldList.ViewModel.Filters) { if (field.FieldInfo == payload.DraggedField.FieldInfo && this.Context is TreeNodeElement )) { e.CanDrop = false; this.payload.SetDestination(null); this.payload.RemoveFromSource = false; return; } } } base.OnPreviewDragOver(e); } private Telerik.WinControls.UI.PivotFieldList.IField GetField(object context) { RadListVisualItem listItem = context as RadListVisualItem; TreeNodeElement treeItem = context as TreeNodeElement; PivotFieldListItemButton button = context as PivotFieldListItemButton; if (button != null) { listItem = button.Owner; } Telerik.WinControls.UI.PivotFieldList.IField field1 = null, field2 = null; if (listItem != null && listItem.Data != null) { field1 = listItem.Data.DataBoundItem as Telerik.WinControls.UI.PivotFieldList.IField; } if (treeItem != null && treeItem.Data != null) { field2 = treeItem.Data.DataBoundItem as Telerik.WinControls.UI.PivotFieldList.IField; } return field1 ?? field2; } }
My pivot grid data size is 90,388 rows, and I export data to xlsx format with SheetName = "data".
The output file generated in this case (correctly) has 65536 rows on sheet "data" and the remaining 24852 rows on the sheet "data_2" (since SheetMaxRows = 65536 and total rows > SheetMaxRows, second sheet "data_2" is added automatically).
But the rows on the sheet "data_2" are written starting from line number 65538. The data on sheet "data_2" starts on line 65538 and goes till line 90389.
Expected:
Actual:
Workaround; use the following custom renderer:
public class MyRenderer : SpreadExportRenderer
{
public override void CreateCellSelection(int rowIndex, int columnIndex)
{
if (rowIndex > (int)Telerik.WinControls.UI.Export.ExcelMaxRows._65536)
{
rowIndex = rowIndex % (int)Telerik.WinControls.UI.Export.ExcelMaxRows._65536 - 1;
}
else
{
rowIndex = rowIndex % (int)Telerik.WinControls.UI.Export.ExcelMaxRows._65536;
}
base.CreateCellSelection(rowIndex, columnIndex);
}
}
Here is my code for localizing the Sum aggregate function. The obtained result is a partial translation:
public RadForm1()
{
PivotGridLocalizationProvider.CurrentProvider = new MyEnglishPivotGridLoclizationProvider();
InitializeComponent();
}
private void RadForm1_Load(object sender, EventArgs e)
{
this.ordersTableAdapter.Fill(this.nwindDataSet.Orders);
this.radPivotGrid1.RowGroupDescriptions.Add(new DateTimeGroupDescription() { PropertyName = "OrderDate", Step = DateTimeStep.Year, GroupComparer = new GroupNameComparer() });
this.radPivotGrid1.RowGroupDescriptions.Add(new DateTimeGroupDescription() { PropertyName = "OrderDate", Step = DateTimeStep.Quarter, GroupComparer = new GroupNameComparer() });
this.radPivotGrid1.RowGroupDescriptions.Add(new DateTimeGroupDescription() { PropertyName = "OrderDate", Step = DateTimeStep.Month, GroupComparer = new GroupNameComparer() });
this.radPivotGrid1.ColumnGroupDescriptions.Add(new PropertyGroupDescription() { PropertyName = "EmployeeID", GroupComparer = new GrandTotalComparer() });
this.radPivotGrid1.AggregateDescriptions.Add(new PropertyAggregateDescription() { PropertyName = "Freight", AggregateFunction = AggregateFunctions.Sum });
this.radPivotGrid1.AggregateDescriptions.Add(new PropertyAggregateDescription() { PropertyName = "Freight", AggregateFunction = AggregateFunctions.Count });
this.radPivotGrid1.FilterDescriptions.Add(new PropertyFilterDescription() { PropertyName = "ShipCountry", CustomName = "Country" });
this.radPivotGrid1.DataSource = this.ordersBindingSource;
}
class MyEnglishPivotGridLoclizationProvider : PivotGridLocalizationProvider
{
public override string GetLocalizedString(string id)
{
switch (id)
{
case PivotStringId.Sum:
return "Soma";
default:
return base.GetLocalizedString(id);
}
}
}
The "Sort" item doesn't seem to be relevant for the report filter. It should be removed from the menu items. However, for the "Hide" item it can be added logic for removing the filter: