Hi,
I am saving last sorting applied of pivot grid in xml. I want to apply this sorting on users next login. Sorting is saved properly but I was unable to apply this sorting at runtime. I refer the pivot grid documentation for sorting and trying exactly same thing but that is not working. My code snippet is as follow:
ISortableOlapDatasource sortDesriptorColl = (MyDashboard.pivotGrid.DataSource as ISortableOlapDatasource);
foreach (ITuple tuple in MyDashboard.pivotGrid.DataSource.Result.ColumnAxis.Tuples) {
if (sortedColumnUniqueName == tuple.Members[0].UniqueName){
if (sortedItem != null && sortedItem.HasValue) {
if (sortDesriptorColl != null) {
sortDesriptorColl.SortDescriptors.Add(new KeyValuePair<ITuple, SortDirection>(MyDashboard.pivotGrid.DataSource.Result.RowAxis.Tuples[0], sortedItem.Value.SortDirection));}}}}
This code run without any error but sorting didn't apply. If I expand the hierarchy of sorted column then it will apply automatically.
if you expand your hierarchy "All Periods" and your first column is "July-2009". If you sort "All Periods" parent level (no matter how with mouse click or from code) then actually your first column from the hierarchy is sorted in this case "July-2009". So yes, it is the same if you sort your first column or the parent of the hierarchy.
About the other question why your code does not work, do you mean the code from your first question? If it is, this does not work because after adding hierarchy descriptor you have to call and Sort method so that sorting to happen.
Greetings,
Dimitrina
If user apply the sorting on some child Header cell, e.g. On Date Column user expand the DataColumn hierarchy to July-2009 and apply sorting on July-2009 HeaderCell. If I apply sorting using following line then it will apply to DataColumn Top Hierarchy (All Periouds). Is that sorting give same result, as sorting on July-2009.
pivotGrid.DataColumns[0].IsSorted= PivotSortDirection.Ascending;
Can you please provide more detail "why my code is not working"?
sorting is not applied because after SortDescriptior is added then sortDesriptorColl.Sort(new KeyValuePair<ITuple, SortDirection>(MyDashboard.pivotGrid.DataSource.Result.ColumnAxis.Tuples[0], sortedItem.Value.SortDirection) method must be applied. Even you can remove the code for added SortDescriptor and call directly Sort method. The other thing is that it must be applied to ColumnAxis not to RowAxis.
Sorry for this misunderstanding we will take care to be corrected in our documentation.
Also there is and easier way to sort from code behind. You can set directly IsSorted property for a column.
pivotGrid.DataColumns[0].IsSorted =
PivotSortDirection.Ascending;
Hope that this will help you.