Unsorted filter

5 posts, 1 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 12 Oct 2011 Link to this post

    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
  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 12 Oct 2011 Link to this post

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

  3. DevCraft banner
  4. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 13 Oct 2011 Link to this post

    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
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 13 Oct 2011 Link to this post

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

  6. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 13 Oct 2011 Link to this post

    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
Back to Top
DevCraft banner