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

[Solved] Sort/filter on a column of type RadGridViewComboBox

13 Answers 765 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 14 Mar 2011, 10:14 AM
Hi,

I've a column which is a RadGridViewComboBox. Before it was only a normal text column and I was able to filter /sort on it, but now since it has to be editable, I had to replace this by a RadGridViewComboBox, but now the little funnel isn't displayed anymore.

Why this?

Here is how I made it:
<telerik:GridViewComboBoxColumn Header="Product"  Width="2*"  DataMemberBinding="{Binding Product}"  DisplayMemberPath="FullDescription" ItemsSource="{Binding Products}"/>


Thank you!

13 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 14 Mar 2011, 10:37 AM
Hello Julien,

Generally, the filtering of the GridViewComboBoxColumn is enabled, but it will be based on the values of the property set in the DataMemberBinding, i.e. the property that comes from the source of the grid. You may test this behavior in our demos. 
In case you decide on filtering based on the displayed value, you will need to implement the logic on your own. A example for this may be found in this blog post. 
On the other hand, you might consider setting the SelectedValueMemberPath property of the column. Its goal is to synchronize the selected value from the RadComboBox to the property of underlaying data item.
  

Kind regards,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Julien
Top achievements
Rank 1
answered on 14 Mar 2011, 01:15 PM
I ensure you that the filter isn't available. I've a ToString override on the bound object which is exactly the value displayed and the value on which I want to do the filter.

I want to keep the same interface than in other column, so I can't use the filter template.

I tried to play with the SelectedValueMemberPath:
<telerik:GridViewComboBoxColumn Header="Product"  Width="2*"  DataMemberBinding="{Binding Product.FullDescription}"  SelectedValueMemberPath="FullDescription"  ItemsSource="{Binding Products}"/>
But with this, I will have only the text into my object that will be changed, not the object itself, and it's not what I want

This is actually working: 
<telerik:GridViewComboBoxColumn Header="Product"  Width="2*"  DataMemberBinding="{Binding Product}" DisplayMemberPath="FullDescription"  SelectedValueMemberPath="FullDescription"  ItemsSource="{Binding Products}"/>

but I can't sort and/or filter like in my screenshot
0
Maya
Telerik team
answered on 14 Mar 2011, 01:40 PM
Hi Julien,

I am sending you a sample project illustrating the implementation of the GridViewComboBoxColumn. It demonstrates a possible approach for sorting it based on a separate property SortID. As far as the filtering is concerned, the only possibility for the enabling this functionality based on the displayed value is to follow the blog post's example. 
Please take a look at the sample project attached and let me know in case of any misunderstandings. Feel free to change as required and send it back if necessary.

 

All the best,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Julien
Top achievements
Rank 1
answered on 15 Mar 2011, 08:48 AM
Hi,

I've only one problem with setting the itemsSource of the GridViewComboBoxColumn in the code behind. If a day we decide to change the order of columns, change type, add converter, ... we have to change this in the code behind too.
We have strict policies in our enterprise, and the most important is to have maintainable software, and this is definitely not the case with this kind of approach.

So how can I do this form the xaml side?
0
Maya
Telerik team
answered on 15 Mar 2011, 08:58 AM
Hi Julien,

When setting the ItemsSource of the GridViewComboBoxColumn, you may take one of the approaches:
1. Set it in the code-behind as demonstrated in the sample project;
2. Define the class where the source for the column in the Resources section and use it as a StaticResource afterwards:

<UserControl.Resources>
   <local:MainPageViewModel x:Key="mainPageViewModel" />
</UserControl.Resources>
...
<telerik:GridViewComboBoxColumn Header="Category"
           DataMemberBinding="{Binding CategoryID}"
           ItemsSource="{Binding Path=Categories, Source={StaticResource mainPageViewModel}}"
           DisplayMemberPath="CategoryName"
           SelectedValueMemberPath="CategoryID" />
  
3. Define the collection for the source of the column as a property of your business object and use the ItemsSourceBinding property of the GridViewComboBoxColumn.

 

Greetings,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Julien
Top achievements
Rank 1
answered on 15 Mar 2011, 09:29 AM
Okay, some questions:

The "SortMemberPath" is the path on objects of the "ItemSources" or of the current row?
If I've to Bind ID instead of the "FullDescription" field, the filter will display my Ids and not the fullText.

I tried to do this:
<telerik:GridViewComboBoxColumn Header="Product"  Width="2*"  
   DataMemberBinding="{Binding Product}"
   DisplayMemberPath="FullDescription" 
   SortMemberPath="FullDescription"
   ItemsSource="{Binding Products}"/>
but I can't filter and if I try to sort, I've this:
A first chance exception of type 'System.ArgumentException' occurred in Telerik.Windows.Data.dll
in the output console
0
Maya
Telerik team
answered on 15 Mar 2011, 09:47 AM
Hi Julien,

The SortMemberPath property of the GridViewComboBoxColumn needs to be set to a property from the source of the RadGridView. Only then the grid will know which property to sort on. The fact that the filter shows the ID-s instead of the displayed values is the expected behavior as mentioned above since the grid is aware only of the properties of its own business object, not the one of the column.  

Best wishes,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Julien
Top achievements
Rank 1
answered on 15 Mar 2011, 10:12 AM
So you don't have any solution to give to me to:

-Have a radGridViewComboBox
-Sort/filter on this column
-Keep filter possibility as "StartsWith" and its layout

Because I can't use SortMemberPath, because you said to me I've to bind on the "ID"(the key of my external object), and if I bind on the ID, the object will not be updated, so I can't do a SortMemberPath on a property of the object(which isn't updated).

It's just unbelievable, I'm asking a very simple thing...


Why this:
<telerik:GridViewComboBoxColumn Header="Product"  Width="2*"  
                                                    DataMemberBinding="{Binding Product}" 
                                                    ItemsSource="{Binding Products}"/>

Doesn't work? I've a ToString override which display things correctly, why your column isn't able to use it to filter/sort?

(Sometimes I don't receive mails of updated threads)
0
Julien
Top achievements
Rank 1
answered on 15 Mar 2011, 11:26 AM
I tried this:

<telerik:GridViewComboBoxColumn Header="Product"  Width="2*" 
   DataMemberBinding="{Binding Product}"
   ItemsSource="{Binding Products}"
   DisplayMemberPath="FullDescription"
   SortMemberPath="Product.FullDescription">
   <telerik:GridViewComboBoxColumn.FilteringControl>
     <GridFilter:DisplayColumnFilter/>
   </telerik:GridViewComboBoxColumn.FilteringControl>
 </telerik:GridViewComboBoxColumn>

The DisplayColumnFilter is basically the same as the exemple in your code, I just adapted it for our coding guildelines.

But with that I still don't get any way to filter.

So I've done this:
<telerik:GridViewComboBoxColumn Header="Product"  Width="2*" 
   DataMemberBinding="{Binding BdcProduct}"
   SelectedValueMemberPath="BdcIdentity"
   ItemsSource="{Binding Products}"
   DisplayMemberPath="FullDescription">
   <telerik:GridViewComboBoxColumn.FilteringControl>
     <GridFilter:DisplayColumnFilter/>
   </telerik:GridViewComboBoxColumn.FilteringControl>
 </telerik:GridViewComboBoxColumn>

With this I get the filter, but with that I cannot use anymore the SortMemberPath because the object "Product" isn't updated by the column, so I can't do sort on the FullDescription.

So how should I do this now?

Thank you

Julien
0
Julien
Top achievements
Rank 1
answered on 15 Mar 2011, 11:37 AM
One more problem with the custom columnFilter:

Let's imagine I've 3 possibility: A, B, C, I've two elements with value A, two with value B, two with C

I open the filter TAB, I select only A and B:
Okay, I've A and B are displayed: 4 elements

I open the filter again, I Select only "C":
I've no more elements, event if really I've elements with this values.

It seems it only removes non-matching elements of the previous set.
0
Pavel Pavlov
Telerik team
answered on 18 Mar 2011, 01:13 PM
Hello Julien,

The painless approach here would be to expose the value of "ToString()" as  a property of the business object besides the ID property.

This will save a lot of troubles . In case you can not directly modify the business object, you can always provide a View model between the original data and RadGridView.

Regards,
Pavel Pavlov
the Telerik team
0
Julien
Top achievements
Rank 1
answered on 18 Mar 2011, 01:36 PM
I already done that, the "FullDescription" property is only a call to the ToString() property
0
Pankaj
Top achievements
Rank 1
answered on 18 Nov 2011, 06:26 AM
Hi Maya,

1.) I followed your posts in this thread and attached project. Setting SortMemberPath to some property of Itemssource of gridview works for me. but it sorts on the id and not the description. Could you please suggest how can I sort on the description of combobox column?

2.) Secondly, I want to handle the sorting state 'None' so as to sort the records in ascending order of first column. I have added following code to implement this
private void playersGrid_Sorting(object sender, GridViewSortingEventArgs e)
      {
          if (e.NewSortingState == SortingState.None)
          {
              this.playersGrid.SortDescriptors.Clear();
              SortDescriptor descriptor = new SortDescriptor();
              descriptor.Member = "Name";
              descriptor.SortDirection = System.ComponentModel.ListSortDirection.Ascending;
              //ColumnSortDescriptor csd = new ColumnSortDescriptor();
              //Telerik.Windows.Controls.GridView.ColumnSortDescriptor csd = new Telerik.Windows.Controls.GridView.ColumnSortDescriptor();
              //csd.Column = this.playersGrid.Columns[0];
              //csd.SortDirection = System.ComponentModel.ListSortDirection.Ascending;
              this.playersGrid.SortDescriptors.Add(descriptor);
          }
      }

I have tried to use sort descriptor and ColumnSortDescriptor but none of these worked for me. Please suggest how can i acomplish this behaviour.

Tags
GridView
Asked by
Julien
Top achievements
Rank 1
Answers by
Maya
Telerik team
Julien
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Pankaj
Top achievements
Rank 1
Share this question
or