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

Property from sort descriptors.

5 Answers 233 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chad
Top achievements
Rank 1
Chad asked on 27 Nov 2015, 03:29 AM

We need to send the grid sorting configuration to the backend system. Is the below approach using the UniqueName property going to be reliable? If not can you please advise on the most reliable means to get the information necessary to extract the bound property name.

 Thank you.

foreach(Telerik.Windows.Controls.GridView.ColumnSortDescriptor desc in uxRadGridControl.SortDescriptors)
            {
                var x = desc.SortDirection;
                var f = desc.Column.UniqueName;
            }

 

5 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 27 Nov 2015, 04:30 PM
Hello Chad,

Your approach seems fine if you're using ColumnSortDescriptor.
If you prefer, I would suggest the following approach in order to achieve the desired result, provided you use SortDescriptors:

var descriptors = this.radGridView.SortDescriptors;
foreach (SortDescriptor desc in descriptors)
{
    var direction = desc.SortDirection;
    var property = desc.Member;
}

I would also suggest having a look at the Programmatic Sorting section of our documentation if you haven't done so already.
 
Please let me know if this works for you.

Regards,
Dilyan Traykov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Chad
Top achievements
Rank 1
answered on 28 Nov 2015, 01:08 AM
Thanks Dilyan. I indeed prefer .Member over .Column.UniqueName, it will make me sleep much better at night.
0
Chad
Top achievements
Rank 1
answered on 29 Nov 2015, 03:29 AM

Well, guess I'm back to using ".Column.UniqueName".

 Unable to cast object of type 'Telerik.Windows.Controls.GridView.ColumnSortDescriptor' to type 'Telerik.Windows.Data.SortDescriptor'.

Dilyan, I really feel uncomfortable to use the UniqueName approach as it feels there's very little guarantee for it to always be the same as the member name. Any advice regarding this would be greatly appreciated

0
Dilyan Traykov
Telerik team
answered on 30 Nov 2015, 12:03 PM
Hello Chad,

You are given this exception for one of two reasons:
1) You're sorting RadGridView through the UI, so a ColumnSortDescriptor is added to the SortDescriptors collection.

2) You've defined a ColumnSortDescriptor in your SortDescriptors collection either programmatically or through XAML.

I want to note that If you do not explicitly set the UniqueName for your column, it will be the same as the property to which you're binding the DataMemberBinding. So I believe there is nothing to worry about and you should have no problems using the ColumnSortDescriptor and its Column.UniqueName.

Regards,
Dilyan Traykov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Chad
Top achievements
Rank 1
answered on 01 Dec 2015, 05:10 AM

Hi Dilyan,

Yes, we are doing no.1 allowing the user to determine the sort order on the server data before running their search/page requests. We're currently using Column.UniqueName and all is working great, I'm just a bit concerned that at some point the value stored in UniqueName might change as no one can be held to guaranteeing it being the member name, the only guarantee is that it should be a unique name. As for now, you seem pretty confident that it wouldn't be used to store any other unique data so that's good enough for me.

Thanks for for your time.

Tags
GridView
Asked by
Chad
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Chad
Top achievements
Rank 1
Share this question
or