Hi,
I am using an XmlaDataSource to populate my XamPivotGrid, and would like to be able to not show the all members and just have the child items expanded. Does anyone know how to achieve this?
I have been able to do this when using FlatDataSource by not adding All levels to the hierarchy descriptor, but I cannot seem to accomplish the same using the XmlaDataSource.
Thanks,
Phil
Hello Phil,
Thank you for your post.
I have been investigating into this issue, and with the current implementation of the XamPivotGrid and the usage of an XmlaDataSource, custom hierarchy descriptors are not supported. This is because the XmlaDataSource essentially creates hierarchies based on the database that it is using as its source, and so unfortunately the same logic for the FlatDataSource will not work here. I do believe that the simplest way for this to work would be to use hierarchy descriptors, though, so if you would like to see the ability to use hierarchy descriptors with an XmlaDataSource in the XamPivotGrid, I would recommend that you suggest a new product idea for it at http://ideas.infragistics.com. This site will place you in direct communication with our product management teams who plan and prioritize upcoming features and products based on user and community feedback.
Instead, I would recommend that you go through the XamPivotGrid.GridLayout.ColumnHeaderCells or the XamPivotGrid.GridLayout.RowHeaderCells collection and loop through each PivotHeaderCell object that exists in these collections (foreach(PivotHeaderCell cell in myPivotGrid.GridLayout.ColumnHeaderCells){}). By using the following code, where item is your PivotHeaderCell, you can check the header cell's content to see if it contains the word "All": item.Control.Content.ToString().Contains("All");. If this condition is true, I would recommend that you set item.Row.Height = 0;.
You may also wish to consider going through the XamPivotGrid.DataColumns and the XamPivotGrid.DataRows collections to do this as well. Here is a link to a separate forum thread which describes how you could do this: http://ko.infragistics.com/community/forums/p/49509/274950.aspx.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Thanks for the reply.
I have tried what you suggested as per the code below, but unfortunately nothing happens (the AllMember cells are still showing)
Any suggestions as to what i might be doing wrong?
Thanks
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); pivotGrid.DataSource.Columns.CollectionChanged += Columns_CollectionChanged; pivotGrid.DataSource.Rows.CollectionChanged += Rows_CollectionChanged; pivotGrid.DataSource.Measures.CollectionChanged += Measures_CollectionChanged; pivotGrid.DataSource.Filters.CollectionChanged += Filters_CollectionChanged; } private void Filters_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { Squash(); } private void Measures_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { Squash(); } private void Rows_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { Squash(); } private void Columns_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { Squash(); } private void Squash() { foreach (var dataColumn in pivotGrid.DataColumns) { Debug.Print( "Column:" + dataColumn.HeaderText); if (dataColumn.HeaderText.Contains("All")) { dataColumn.ColumnWidth = 0; } } foreach (var dataRow in pivotGrid.DataRows) { Debug.Print("Row:" + dataRow.HeaderText); if (dataRow.HeaderText.Contains("All")) { dataRow.Height = 0; } } foreach (PivotHeaderCell cell in pivotGrid.GridLayout.RowHeaderCells) { SquashCell(cell); } foreach (PivotHeaderCell cell in pivotGrid.GridLayout.ColumnHeaderCells) { SquashCell(cell); } } private static void SquashCell(PivotHeaderCell cell) { if (cell.Control == null || cell.Control.Content == null) return; if (cell.Control.Content.ToString().Contains("All")) { cell.IsExpanded = true; if (cell.Row != null) cell.Row.Height = 0; if (cell.Column != null) cell.Column.ColumnWidth = 0; } } }
THanks Andrew - I gave your suggestions a try. It did work occasionally but there were a few problems:
-SOmetimes nothing happens: The events did not seem to always fire meaning that the IsExpanded did not get set some of the time.
-When adding another dimension to rows, the dimension previously added to columns would get collapsed again.
-When removing and re-adding the same dimension a couple of times to the columns, the grid gets into an endless "flickering" state. presumably and endless loop.
Overall I'm not sure i can take this approach as things stand, as it seems to have destabilized the grid.
THanks,
Thank you for your response.
I have reproduced the destabilization of the XamPivotGrid that you are seeing. It appears that the removal and re-add of a member in the XamPivotGrid is dropping it into an infinite loop of expansion and collapse of the members that contain the word "All."
I am currently looking into a way to modify the sample project that I had sent you to prevent this. I currently have it preventing the infinite loop of expansion and collapse, but when collapsing, the full column structure collapses currently. I am also somewhat unsure of how to get the multiple dimensions in the XamPivotGrid to work, as this appears to destabilize the grid a bit further.
I should have some more information for you on this matter soon. Please let me know if you have any other questions or concerns on this matter.
ok thanks for the continued efforts. The sooner we can get a solution here the better. Look forward to hearing from you.
Hi Andrew,
I also found that i was not able to hide the AllMembers successfully for the rows.
Whilst the following works for teh columns in your example:
foreach (PivotHeaderCell cell in PivotGrid1.GridLayout.ColumnHeaderCells) { if (cell.Column == pdc) { cell.Row.Height = 0; } }
the equivalent below for the rows does not work:
if (cell.Row == pdr) { cell.Row.Height = 0; } }
I also tried
cell.COlumn.MinWidth=0;
cell.Column.ColumnWidth=0;
but that didnt work either.
Any ideas?
I have been investigating into this issue a bit further with my colleagues, and the current behavior you are seeing is actually expected. With the XamPivotGrid's default layout, the Rows column has a constraint in which it must extend to the length of the RowHeaderPanel, which is the panel just above the rows that you are adding to your XamPivotGrid. The reason you are seeing this behavior that you are seeing is not because the call to cell.Row.Height for your rows is not working, but rather because it is working, but is triggering an internal property changed notification that notifies the grid that the length of the RowHeaderPanel will not be met, and so the cell.Row.Height gets set back to what it was before. You may ask, "why not just modify the width of the RowHeaderPanel," but this would destabilize the grid, as this is used in the positioning of the data cells in the XamPivotGrid. This constraint essentially disallows the removal of the "All Members" header in the Row area of the XamPivotGrid, besides from hiding the PivotRowHeaderCellControl by setting its Visibility property. However, doing this will leave a large white space where it originally existed, so I wouldn't recommend this either.
Instead, I would recommend using either the XamPivotGrid's CompactLayout or SuperCompactLayout. These layouts can be set on the XamPivotGrid by setting the AllowCompactLayout or the AllowSuperCompactLayout properties to "True." These "compact layouts" directly effect the Rows portion of the XamPivotGrid, but have no real effect on the columns part, so I would recommend that you continue with the way the columns are currently being hidden to that end.
With the CompactLayout of the XamPivotGrid, the cell.Row.Height = 0; call for the rows will work, but a small expansion/collapse indicator will still be present. If you do not want this, I would recommend continuing with the SuperCompactLayout in the XamPivotGrid, which will eliminate the "All Members" header as soon as that header is expanded. You can expand this header in the same fashion as is demonstrated in the original sample project I had sent you. One thing to note, though, is that the SuperCompactLayout will have the children essentially appear over the top of each other with no indentation. You can set this indentation by setting the SuperCompactLayoutIndent property on the XamPivotGrid to the pixel value that you wish your indentation to show as.
The real issue here truly comes in when you are looking to collapse the headers in the XamPivotGrid or add multiple members to each of the XamPivotGrid columns or rows. With the XmlaDataSource, these headers will come in essentially as soon as they are loaded from the attached database, and as the XamPivotGrid has a massive amount of different layouts that can take shape, it is currently very difficult to catch these members as they load, and hide their row, but ensure that they are expanded first. Truly the best recommendation I can give you with the current implementation of the XamPivotGrid is that you consider refactoring the underlying database to your XmlaDataSource, or that you load the database into a separate object and create a FlatDataSource out of the database that you are using for your XmlaDataSource so that you can provide the hierarchy descriptors to the source collection of your grid and hide the "All Members" parts that way. Otherwise, I would recommend that you create a new product idea for this particular feature in the XamPivotGrid, by visiting http://ideas.infragistics.com.