The A-Z button doesn't make the grid sort the properties alphabetically

5 posts, 1 answers
  1. BENN
    BENN avatar
    59 posts
    Member since:
    Dec 2011

    Posted 12 Jul Link to this post

    It seems that all what the IsGrouped property does is decide if the properties appeared as grouped or not, and clicking on A-Z doesn't sort them from A-Z (unlike for example in Visual Studio).

    I've created an example where the item is:

    public class MyClass
    {
        [Display(Name="A-Name", GroupName="Group2", Order=9)]
        public string AName { get; set; }
     
        [Display(Name="B-Name", GroupName="Group2", Order=7)]
        public string BName { get; set;}
     
        [Display(Name = "C-Name", GroupName = "Group2", Order = 8)]
        public string CName { get; set; }
     
        [Display(Name = "D-Name", GroupName = "Group1", Order = 3)]
        public string DName { get; set; }
     
        [Display(Name = "E-Name", GroupName = "Group1", Order = 2)]
        public string EName { get; set; }
     
        [Display(Name = "F-Name", GroupName = "Group1", Order = 1)]
        public string FName { get; set; }
     
    }

     

    When the A-Z button is selected, the properties are ordered as:

    F-Name

    E-Name

    D-Name

    B-Name

    C-Name

    A-Name

     

     

    Just like the order I've defined. But with any other normal property grid, the order only affects the items when they are grouped.

    The visibility of these buttons is called "SortAndGroupButtonsVisibility", so theoretically, this button should have sorted the properties alphabetically.

     

  2. Answer
    Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    279 posts

    Posted 15 Jul Link to this post

    Hello Benn,

    The PropertyGrid control is designed so that the Order has priority over the alphabetical sorting. You can review the following thread where a similar topic was discussed - How to disable the alphabetical sort in the grouped view. Removing the order of the properties would cause RadPropertyGrid`s alphabetical sorting to be applied. 

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. BENN
    BENN avatar
    59 posts
    Member since:
    Dec 2011

    Posted 17 Jul in reply to Stefan Nenchev Link to this post

    Yes, but when working with A-Z, any user would expect the properties to be ordered from A-Z, and not just appear as they are not, but without the groups header (Look on how visual studio implements its property grid).

     

    Anyway, since you are not giving me a solution, then I had to look for one myself. It involves changing the source code, but since I already must recompile the source code since your License agreement enforces me to do so (Protecting your assembly by uncommenting some code in the assembly protection). It is just a headache to maintain the changes (and some fixes) when a new Rad Controls version is released.

    If anyone is interested in a solution, then find a converter named: FlatItemSourceConverter

    Then change its code to:

    public class FlatItemSourceConverter : IValueConverter
    {
        /// <summary>
        /// Sifts out the root properties.
        /// </summary>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var currentIEnumerable = value as IEnumerable<PropertyDefinition>;
            if (currentIEnumerable != null && currentIEnumerable.IsNotEmpty())
            {
                if (currentIEnumerable.ElementAt(0).ParentPropertyGrid != null && currentIEnumerable.ElementAt(0).ParentPropertyGrid.IsGrouped)
                {
                    var res = currentIEnumerable.AsQueryable<PropertyDefinition>()
                    .Where(new FilterDescriptorCollection() { new FilterDescriptor() { Member = "IsFiltered", Operator = FilterOperator.IsEqualTo, Value = true } })
                    .Sort(new SortDescriptorCollection() { new SortDescriptor() { Member = "OrderIndex" }, new SortDescriptor() { Member = "DisplayName" } });
                    return res;
                }
                else
                {
                    var res = currentIEnumerable.AsQueryable<PropertyDefinition>()
                    .Where(new FilterDescriptorCollection() { new FilterDescriptor() { Member = "IsFiltered", Operator = FilterOperator.IsEqualTo, Value = true } })
                    .Sort(new SortDescriptorCollection() { new SortDescriptor() { Member = "DisplayName" } });
                    return res;
                }
            }
            return value;
        }
     
        /// <summary>
        /// Not used.
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
     
        private static IFilterDescriptor SearchFilterDescriptor { get; set; }
    }

     

    By this way, the properties are ordered alphabetically when the properties are not grouped, and by OrderIndex and then alphabetically (if few properties share the same OrderIndex) if grouped.

     

    And as a remark, the thread that you've mentioned is called "How to disable alphabetical sort in the grouped view", and not "How to disable alphabetical soft". People were specifically asking to disable the alphabetical sorting, and giving controlled order in the grouped view only.

  5. BENN
    BENN avatar
    59 posts
    Member since:
    Dec 2011

    Posted 20 Jul in reply to BENN Link to this post

    There is one more change that is required for it to work (the code above fixes the problem for Hierarchical render mode, but for flat mode you also need to:

     

    File: PropertyGridPresenter.cs

    On function called UpdateContent

    Replace: this.Content = this.RetrieveNestedPropertyDefinitions(this.ProcessPropertyDefinitionCollection(this.PropertyDefinitions);

     

    With:

    this.Content = this.RetrieveNestedPropertyDefinitions(this.ProcessPropertyDefinitionCollection(this.PropertyDefinitions)
                                .AsQueryable<PropertyDefinition>().Sort(new SortDescriptorCollection() { new SortDescriptor() { Member = "DisplayName" } }).Cast<PropertyDefinition>());

     

    meaning:

    if (this.RenderMode == RenderMode.Flat)
    {
        if (this.IsGrouped)
        {
            if (shouldUpdateGroups)
            {
                var groupedData = this.ProcessPropertyDefinitionCollection(this.PropertyDefinitions).GroupBy(p => p.GroupName);
                this.ClearSubscriptions();
                this.GroupList = groupedData.Select(g => new GroupDefinition(g.Key, g)).ToList<GroupDefinition>();
                this.GenerateSubscriptions();
            }
     
            this.Content = this.GetGroupedContent(this.GroupList);
        }
        else
        {
            if (this.PropertyDefinitions != null)
            {

                     // This is the line that need to be changed!!!

                 this.Content = this.RetrieveNestedPropertyDefinitions(this.ProcessPropertyDefinitionCollection(this.PropertyDefinitions)

                    .AsQueryable<PropertyDefinition>().Sort(new SortDescriptorCollection() { new SortDescriptor() { Member = "DisplayName" } }).Cast<PropertyDefinition>());
            }
        }

  6. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    279 posts

    Posted 20 Jul Link to this post

    Hello Benn,

    Thank you for devoting your time to finding a solution for your requirement and providing it to the others that might find it useful. We have discussed the functionality and decided that at this point such change is not required, but in case more customers express their desire of adding such - we will reconsider it. With this in mind, I have created a Feature Request item in our Ideas & Feedback portal which you can find at the following page - Add an option to ignore OrderIndex when Alphabetical Sorting is applied. Please vote for the item in order to increase its priority.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready