none
Pivot Viewer Sort Order

    Question

  • By default, the Pivot Viewer sorts items in the left column by the number of items in that group. Is there a way to make it default to A-Z sort?

     

     

    Friday, December 30, 2011 3:19 PM

Answers

  • The PivotViewerStringProperty has a Sorts property on it.  The property is a collection of comparers to use in sorting the values in a string filter.  If you examine the default values of this property, you will notice 2 items in it (the Quantity and then the A-Z).  Simply reversing the positioning of these items will change their order (and thus the default view).  Here is a quick example:

    var prop = pViewer.PivotProperties[1] as PivotViewerStringProperty;
    prop.Sorts = new ObservableCollection<KeyValuePair<string, IComparer<string>>>(prop.Sorts.Reverse());
    
    Friday, December 30, 2011 11:29 PM
  • Hi,

    Is there a way to do this in the HTML of the page? You see, I'm an IT guy, not a programmer, so I just found a sample viewer online and used that. Thanks!

    As far as I know, the method Tony.Champion provided is correct. There is not a good method to do it the HTML of the page.

    Thursday, January 05, 2012 5:50 AM

All replies

  • Post your Pivot Table Query here.

    regards

    Savia

    Friday, December 30, 2011 11:11 PM
  • The PivotViewerStringProperty has a Sorts property on it.  The property is a collection of comparers to use in sorting the values in a string filter.  If you examine the default values of this property, you will notice 2 items in it (the Quantity and then the A-Z).  Simply reversing the positioning of these items will change their order (and thus the default view).  Here is a quick example:

    var prop = pViewer.PivotProperties[1] as PivotViewerStringProperty;
    prop.Sorts = new ObservableCollection<KeyValuePair<string, IComparer<string>>>(prop.Sorts.Reverse());
    
    Friday, December 30, 2011 11:29 PM
  • Is there a way to do this in the HTML of the page? You see, I'm an IT guy, not a programmer, so I just found a sample viewer online and used that. Thanks!

    Wednesday, January 04, 2012 3:08 PM
  • Hi,

    Is there a way to do this in the HTML of the page? You see, I'm an IT guy, not a programmer, so I just found a sample viewer online and used that. Thanks!

    As far as I know, the method Tony.Champion provided is correct. There is not a good method to do it the HTML of the page.

    Thursday, January 05, 2012 5:50 AM
  • So if you wanted to do a custom sort (aka Months) how would you creat and wire it up?

    Thursday, January 19, 2012 9:16 PM
  • I have  a question, I've been reading up on this, I'm not a programmer but an IT Guy...

     

    I've seen in a few post the ability to show the current "state" in the standalone view you could click CTRL+ALT+U to get the "state" added to the URL. Like this file:///C:/Godaddy/Current/Projects/Pivot/Crafting/Publish/CraftingPivotv0018.cxml#%24facet0%24=Tag&%24view%24=1&Tag=EQ.BOY&Tag=EQ.FACE

    Everything after the cxml# is the "state" to my understanding.

    I also saw a demo where they added a field that showed this state in the silverlight APP live.

    There was a Demo where they show using the forward and back buttons of the browser when allowing history control.

    Why then couldn't you use the history control demo where the silverlight viewer is looking for the state in the URL tag, this way you could also Favorite a "state" as is which would be very nice.

    If you can pass back and forth then you should be able to pass a saved URL with a set filter, sort ie month... this doesn't control pan or zoom in my understanding.

    ONCE MORE please understand I'm not a programmer but I'm working on a project where I'd like to do this related to each person having their own saved view which can be loaded as a favorite link/bookmark or as a saved file in their profile.

    Both Demos where videos that were linked from here.

    Thoughts?

     

     

    Wednesday, February 01, 2012 8:34 PM
  • If you didn't want to save the state internally and wanted to do it via the URL, you can.  It would be a simple matter of setting and receiving the # portion of the site.  In fact I would do this via the navigation framework if you were looking for a place to research.  PivotViewer doesn't handle this out of the box howerver.

    As far as getting/setting the state from the PivotViewer, you have a couple of options.  If you are just looking at filter, you can do that with the Filter property.  If you want the complete state, you need to look at the following methods: SerializeViewerState, SetViewerState.

    Thursday, February 02, 2012 7:39 AM
  • So if you wanted to do a custom sort (aka Months) how would you creat and wire it up?

    Custom sorts are created as extensions to the FacetCategory element at the top of your CXML. For example months would look like this:

    <FacetCategory Name="Month" Type="String" P:IsFilterVisible="true" P:IsWordWheelVisible="true" P:IsMetaDataVisible="true">
      <Extension>
    	<P:SortOrder Name="Month">
    	  <P:SortValue Value="Jan" />
    	  <P:SortValue Value="Feb" />
    	  <P:SortValue Value="Mar" />
    	  <P:SortValue Value="Apr" />
    	  <P:SortValue Value="May" />
    	  <P:SortValue Value="Jun" />
    	  <P:SortValue Value="Jul" />
    	  <P:SortValue Value="Aug" />
    	  <P:SortValue Value="Sep" />
    	  <P:SortValue Value="Oct" />
    	  <P:SortValue Value="Nov" />
    	  <P:SortValue Value="Dec" />
    	</P:SortOrder>
      </Extension>
    </FacetCategory>
    Tuesday, February 07, 2012 8:06 PM
  • Hello!

    I (or my customer) also wants, that the sort order of the facet-categories should be A-Z by default.

    But we are using the "old" PV, which has not the "PivotProperties".

    Also I can not change the CXML, because it is dynamically generated.

    I already can "dig down" into the CustomAccordionItems/FacetCategories.

    But there I did not find a way to change the sort order of the facets.

    Thanks in advance for any hints!

    Regards,

    HoschyH

    Friday, February 17, 2012 5:03 PM
  • The PivotViewerStringProperty has a Sorts property on it.  The property is a collection of comparers to use in sorting the values in a string filter.  If you examine the default values of this property, you will notice 2 items in it (the Quantity and then the A-Z).  Simply reversing the positioning of these items will change their order (and thus the default view).  Here is a quick example:

    var prop = pViewer.PivotProperties[1] as PivotViewerStringProperty;
    prop.Sorts = new ObservableCollection<KeyValuePair<string, IComparer<string>>>(prop.Sorts.Reverse());
    

    Hi Tony,

    This looks like it's for the new version of PivotViewer (Silverlight 5). Any ideas on how to do the same thing with the Silverlight 4 version?

    Thanks!

    Tuesday, February 21, 2012 3:40 PM
  • Tony, scratch that... I just went ahead and upgraded to Silverlight 5 and got it working with some help from your blog.

    In case anyone else is interested, here is my MainPage.xaml:

    <UserControl x:Class="MyPivotViewer.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:pivot="clr-namespace:System.Windows.Controls.Pivot;assembly=System.Windows.Controls.Pivot"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
    
        <Grid x:Name="LayoutRoot" Background="White">
            <pivot:PivotViewer x:Name="pViewer" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        </Grid>
    </UserControl>
    

    And my MainPage.xaml.cs:

    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Controls.Pivot;
    using System.Windows.Controls.Pivot.Utilities;
    
    namespace MyPivotViewer
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                pViewer.Loaded += new RoutedEventHandler(pViewer_Loaded);
            }
    
            private CxmlCollectionSource _cxml;
    
            void pViewer_Loaded(object sender, RoutedEventArgs e)
            {
                string collection = App.Current.Host.InitParams["initialCollectionUri"].ToString();
                _cxml = new CxmlCollectionSource(new Uri(collection, UriKind.Absolute));
                _cxml.StateChanged += _cxml_StateChanged;
            }
    
            void _cxml_StateChanged(object sender, CxmlCollectionStateChangedEventArgs e)
            {
                if (e.NewState == CxmlCollectionState.Loaded)
                {
                    foreach (var prop in _cxml.ItemProperties)
                    {
                        if (prop is PivotViewerStringProperty && 
                            prop.Options.HasFlag(PivotViewerPropertyOptions.CanFilter))
                        {
                            var _prop = prop as PivotViewerStringProperty;
                            _prop.Sorts = new ObservableCollection<KeyValuePair<string,IComparer<string>>>(_prop.Sorts.Reverse());
                        }
                    }
                    pViewer.PivotProperties = _cxml.ItemProperties.ToList();
                    pViewer.ItemTemplates = _cxml.ItemTemplates;
                    pViewer.ItemsSource = _cxml.Items;
                }
            }
        }
    }
    
    • Proposed as answer by ClipFlair Monday, November 04, 2013 10:30 AM
    Wednesday, February 22, 2012 1:13 AM