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

Defining ColumnSortDescriptor i Xaml

10 Answers 774 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Inger Marie
Top achievements
Rank 1
Inger Marie asked on 13 May 2011, 12:29 PM
I haven't seen any exampels of how to do this, though this one shows how to do it in the code behind (http://www.telerik.com/community/forums/wpf/gridview/sort-arrow.aspx).

In the documentation (http://www.telerik.com/help/silverlight/gridview-sorting-programmatic.html), it shows this:
<telerik:RadGridView x:Name="radGridView"
                        
AutoGenerateColumns="False">
   
<telerik:RadGridView.SortDescriptors>
       
<telerik:SortDescriptor Member="Title"
                                   
SortDirection="Ascending" />
   
</telerik:RadGridView.SortDescriptors>
   
...
</telerik:RadGridView>


However, Member is not a property on SortDescriptor.

I tried this instead:


        <telerik:ColumnSortDescriptor   SortDirection="Ascending"
                                                Column="{Binding ElementName=nextContactColumn}">
                </telerik:ColumnSortDescriptor>

And got the error: Object reference not set to an instance of an object.

How do I in XAML tell the RadGridView to sort by a column

10 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 13 May 2011, 12:36 PM
Hello Inger Marie,

Column descriptors can only be added in code-behind. 


Kind regards,
Milan
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
hermann
Top achievements
Rank 1
answered on 12 Dec 2011, 06:00 PM
Hi,
can you then please remove it in the XAML example
Telerik\RadControls for WPF Q3 2011\Demos\Examples\GridView\Sorting\Example.xaml?

When will SortColumnDescriptors work in XAML as well?

Regards,
Hermann
0
Maya
Telerik team
answered on 13 Dec 2011, 07:28 AM
Hi Hermann,

Defining ColumnSortDescriptor in xaml is not supported. So, you can use the approach illustrated in the example you mentioned. Do you have any difficulties with it ? 
 

Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Accepted
hermann
Top achievements
Rank 1
answered on 13 Dec 2011, 08:43 AM
Hi again,
actually using the XAML snippet from
Telerik\RadControls for WPF Q3 2011\Demos\Examples\GridView\Sorting\Example.xaml
works quite well,
<telerik:RadGridView
Name="radGridView5"
ItemsSource="{Binding IncomingOrders}"
ShowInsertRow="False"
AutoGenerateColumns="False"
AlternationCount="2"                   
IsReadOnly="True"
SelectionMode="Single"
>
<telerik:RadGridView.SortDescriptors>
<telerik:ColumnSortDescriptor Column="{Binding Columns\[radGridView5.Priority.Shortcut\], ElementName=radGridView5}"
    SortDirection="Ascending" />
</telerik:RadGridView.SortDescriptors>
 
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding Priority.Shortcut}" Header="Priorität" UniqueName="radGridView5.Priority.Shortcut"/>
...

the column gets sorted
but when I serialize the whole grid using PersistenceFramework's PersistenceManager.Save()
as shown in example
Telerik\RadControls for WPF Q3 2011\Demos\Examples\PersistenceFramework\GridViewCustomSerialization
Save() fails in GridViewCustomPropertyProvider.ProvideValue()
foreach (ColumnSortDescriptor descriptor in gridView.SortDescriptors)
{
    proxies.Add(new SortDescriptorProxy()
    {
        ColumnUniqueName = descriptor.Column.UniqueName,
        SortDirection = descriptor.SortDirection,
    });
}
since the Column property of the descriptor is null!!!
So, what has to be done to make it work?
Kind regards,
Hermann
0
Maya
Telerik team
answered on 16 Dec 2011, 01:02 PM
Hi Hermann,

I have tried to reproduce the issue you reported, but unfortunately without any success. Could you take a look at the sample attached to verify whether you can get the same exception on it ?
 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
hermann
Top achievements
Rank 1
answered on 16 Dec 2011, 05:00 PM
Hello Maya,
I have figured out why my source was not working.
There are several traps in the code - and my understanding of it
and maybe someone else can take advantage of this posting and save time to do more funny stuff.
Note: This is for WPF Q3 2011

  1. Order is not important. In the Telerik example (the zipped file above), the XAML sortdescriptor definition comes after the columns definition, but it works also with sortdescriptor def before columns def  (- the more natural way for me)
  2. Telerik example uses a backslash as -kind of- string terminator for the ColumnSortDescriptor Column binding. This is a trap because it allows several possible ways to see it
    (a) the "\" is a special character to allow parsing the square brackets within the xml statement
          (so, ...ColumnSortDescriptor Column="{Binding Columns[\Value\], ... might be interpreted as
          '\]' to allow a special character like
          '\n' or '\{' whereas the first '[\' might be just a typo...
          (I used \[Value\] in my xaml and it worked!)
    (b) the "\" is part of a binding path, so the binding is related to the DataContext
          and [\Value\] would mean:
          bind to the property starting at datacontext's root
          and then use the Value property.
          Btw - if you omit all '\' it will work as well.
    (c) The last sentence of (b) is not correct:
          If you want to persist your gridview's layout, you have to add UniqeName as tagname
          for the PersistenceManager.
          But if you give the column a unique name, the previously working binding of the
          ColumnSortDescriptor fails.
          ColumnSortDescriptor's Column property becomes now null.
          The reason for this is, that the definition of the ColumnsSortDescriptor has to be changed to
          ColumnSortDescriptor Column="{Binding Columns[your_columns_unique_name]
          or [\your_columns_unique_name\] (with or without backslash)

... yes, I know, this is all by design ...
but changing the ColumnsSortDescriptors Column binding path depending on a
property not related to binding at all in the GridViewDataColumn still looks like a bug for me.
... and - as always -  this behaviour is undocumented...

Regards,
Hermann
0
Mauricio
Top achievements
Rank 1
answered on 02 Jan 2012, 12:18 AM
It works in XAML code indeed. Try with this sample.

<telerik:RadGridView ItemsSource="{Binding Clausulas}" SelectedItem="{Binding SelectedClausula}" AutoGenerateColumns="False"  >
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding NumeroClausula}" Header="Número"  />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Texto}" Header="Claúsula" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding NumeroObligaciones}" Header="Obligaciones" TextAlignment="Right" />
    </telerik:RadGridView.Columns>
    <telerik:RadGridView.SortDescriptors>
        <telerik:SortDescriptor Member="NumeroClausula" SortDirection="Ascending" />
    </telerik:RadGridView.SortDescriptors>
</telerik:RadGridView>
0
Maya
Telerik team
answered on 03 Jan 2012, 07:33 AM
Hi Hermann and Mauricio,

Thank you for sharing your thoughts and knowledge on the issue, it could be quite helpful for the community.
Considering the documentation, we will do our best to include some on the topic in one of our next updates of the online help.
We do appreciate your feedback.

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Dariusz
Top achievements
Rank 1
answered on 01 Dec 2017, 08:29 AM
You must check what kind of descriptor (ColumnSortDescriptor or SortDescriptor) is added when You click on column header. I have same problem. In xaml I defined default SortDescriptor and PersistenceManager work well, until I click column header.
0
Dilyan Traykov
Telerik team
answered on 05 Dec 2017, 12:22 PM
Hello Dariusz,

Indeed, the ColumnSortDescriptor and SortDescriptor are simply two implementations of the ISortDescriptor interface and are not interchangeable.

As I could not infer from your last reply, could you please specify whether you're still experiencing an issue with the PersistenceManager and you need assistance or if you managed to resolve it?

I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Inger Marie
Top achievements
Rank 1
Answers by
Milan
Telerik team
hermann
Top achievements
Rank 1
Maya
Telerik team
Mauricio
Top achievements
Rank 1
Dariusz
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or