This is a migrated thread and some comments may be shown as answers.

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

4 Answers 297 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
BENN
Top achievements
Rank 1
BENN asked on 13 Jul 2016, 04:05 AM

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.

 

4 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Nenchev
Telerik team
answered on 15 Jul 2016, 02:18 PM
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.
0
BENN
Top achievements
Rank 1
answered on 17 Jul 2016, 06:12 AM

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.

0
BENN
Top achievements
Rank 1
answered on 20 Jul 2016, 08:00 AM

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>());
        }
    }

0
Stefan Nenchev
Telerik team
answered on 20 Jul 2016, 04:03 PM
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.
Tags
PropertyGrid
Asked by
BENN
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
BENN
Top achievements
Rank 1
Share this question
or