Property from sort descriptors.

6 posts, 0 answers
  1. Chad
    Chad avatar
    21 posts
    Member since:
    Aug 2013

    Posted 26 Nov 2015 Link to this post

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

     

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 27 Nov 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Chad
    Chad avatar
    21 posts
    Member since:
    Aug 2013

    Posted 27 Nov 2015 Link to this post

    Thanks Dilyan. I indeed prefer .Member over .Column.UniqueName, it will make me sleep much better at night.
  5. Chad
    Chad avatar
    21 posts
    Member since:
    Aug 2013

    Posted 28 Nov 2015 Link to this post

    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

  6. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    368 posts

    Posted 30 Nov 2015 Link to this post

    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
  7. Chad
    Chad avatar
    21 posts
    Member since:
    Aug 2013

    Posted 30 Nov 2015 in reply to Dilyan Traykov Link to this post

    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.

Back to Top
UI for WPF is Visual Studio 2017 Ready