Hi,
Is it possible to have show/hide the totals dynamically? Our users would like to do so by clicking a button.
We've been checking these posts:
http://es.infragistics.com/community/forums/t/84334.aspx
http://es.infragistics.com/community/forums/t/56405.aspx
It doesn't work very well. When we need to refresh the grid because the underlying data has changed and call PivotGrid.DataSource.RefreshGrid() the hidden rows come back.
We've tried to do the hiding/showing logic in the PivotGrid.LayoutUpdated event handler but we've noticed something else:
When the totals are hidden and we collapse any level, the level actually disappears until the we call again PivotGrid.DataSource.RefreshGrid(). This only happens when hiding the rows by setting IsVisible to false. If instead we do Height=0 this behaviour doesn't occur.
Is there a better way to handle this? Is it possible to avoid keeping hiding the rows in the LayoutUpdated event handler?
Thanks.
Hi Ribao80,
I'm unable to reproduce this. The sorting button shouldn't be located in the totals cell but in the parent hierarchy cell. I have attached a sample that shows this. When you run the sample, drag the Product dimension to the Rows area and then expand "All Products". You will see that the totals are not visible when Product is expanded. Now press the button at the bottom left of the window to add a new product. You will see it get added to the bottom but the product name starts with an "a" so it should be at the top. Hover the mouse over "All Products" and you will see the sorting button is still visible. Clicking on this will refresh the position of the new product to the top of the list. Just make sure that AllowHeaderRowsSorting and AllowHeaderColumnsSorting are set to true for this to work.
Maybe you have some extra settings on the pivot grid that are interfering with this? Can you try reproducing the issue in my sample and reattaching it so I can take a look?
We've found a problem - if the totals are hidden then there's no icon to click and reorder the rows. When new records are added to the underlying collection and we call PivotGrid.DataSource.RefreshGrid() they're added to the bottom.
Is there an equivalent to the XamDatagrid's Record.RefreshSortPosition() method?
Hi Rob,
Thanks for your answer.
That solution seems to be working for us. I've noticed a glitch where all the records have suddenly collapsed, will let you know if I can reproduce it.
For dynamically hiding and showing totals I don't think there is a better way of doing this other than setting IsVisible to false as shown in those other threads. The issue with your scenario is that since the totals have been hidden, when you collapse the level the visibility isn't being restored. The expansion of the hierarchy when the column/row is collapsed is the same column/row that handles the Totals. So if that column or row is collapsed, when you re-collapse the hierarchy the column or row is no longer visible.
A way you can resolve this is to handle the AxisExpansionChanged event and restore the totals row/column visibility. This event will provide you with a HeaderCell and this object has properties that can allow you to determine if this cell is for the totals or not and then you can reset the visibility. Something like this perhaps:
private void PivotGrid_AxisExpansionChanged(object sender, PivotAxisExpansionChangedEventArgs e){ if (e.HeaderCell.Member.IsTotal) { foreach (PivotDataRow c in pivotGrid.DataRows) { if (c.Tuple.Members.Contains(e.HeaderCell.Member) && !c.IsVisible) { c.IsVisible = true; } } }}
Is anyone looking at this?