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

Unsorted filter

4 Answers 50 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Håkan
Top achievements
Rank 1
Håkan asked on 12 Oct 2011, 03:08 PM
Hi,

I set the ItemsSource on the GridView to a collection that has a specific sort order already defined from the server (not just as easy as sorting on a specific column).
I don't want the user to be able to change the order so I have CanUserSortColumns="False" and also SortingState="None" on the column.

But the filter function seems to do it own sorting. When I click the funnel icon and bring up the FilteringControl, the values in the list of checkboxes are sorted ascending on the column.
I want this list to stay unsorted also, is that possible?

- Regards,
Håkan

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 12 Oct 2011, 04:49 PM
Hi Håkan,

Yes, it is possible to have the values in the list of check boxes unsorted. You could manage the distinct values shown in the FilteringControl inside the DistinctValuesLoading event handler of the RadGridView.

For example, if the column that you apply the filter to is "Property1", then you could load the data unsorted like so:

private void myGrid_DistinctValuesLoading(object sender, Telerik.Windows.Controls.GridView.GridViewDistinctValuesLoadingEventArgs e)
      {
          var sourceCollection = (IEnumerable<Item>)this.myGrid.ItemsSource;
 
          e.ItemsSource = sourceCollection.Select(item => item.Property1).Distinct();
      }

Please check this and let me know if it works for your scenario.
 
Kind regards,
Didie
the Telerik team

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

0
Håkan
Top achievements
Rank 1
answered on 13 Oct 2011, 06:49 AM
Hmm, my column is bound to a Dictionary<int, string> so if I do like this:

var sourceCollection = (IEnumerable<KeyValuePair<int, string>>)this.DataGrid.ItemsSource;
e.ItemsSource = sourceCollection.Select(item => item.Key).Distinct();

The compiler complains, saying that there is no Select method on a IEnumerable<KeyValuePair<int, string>.

I tried to just set e.ItemsSource = sourceCollection since my collection already contains distinct values, but then it will display both Key and Value in the filter like this:
[1, AAA]
[2, BBB]
....

- Regards,
Håkan
0
Rossen Hristov
Telerik team
answered on 13 Oct 2011, 09:41 AM
Hi Håkan,

Have you imported the System.Linq namespace?

Best wishes,
Ross
the Telerik team

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

0
Håkan
Top achievements
Rank 1
answered on 13 Oct 2011, 10:14 AM
Now I feel stupid!

I have done that mistake so many times so I should have learned by now :-)

Thanks, now it works fine!

Regards,
Håkan
Tags
GridView
Asked by
Håkan
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Håkan
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or