Filterable/Sortable Column Chooser for GridView

6 posts, 0 answers
  1. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 02 Feb Link to this post

    Suggested improvements to the GridView ColumnChooser window: 

    Some of my grids offer more than 100 optional columns in the column chooser. Finding a column could be sped up if the column chooser offered a 'Contains' filter.

    Sorting the column in the column chooser

    Hide the background text on the column chooser if it's covered by column buttons. Currently if you have a full column chooser, some black points show through between the column buttons.

    Regards

    erwin

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 03 Feb Link to this post

    Hi Erwin,

    Thank you for your feedback.

    The sorting is already supported and you can set the sort order once the column chooser is shown. You can hide the text as well (use the ColumnChooserCreated event to subscribe to the Shown event):
    private void ColumnChooser_Shown(object sender, EventArgs e)
    {
        var columnChooser = sender as GridViewColumnChooser;
        columnChooser.ColumnChooserControl.ColumnChooserElement.SortOrder = RadSortOrder.Descending;
     
        if (columnChooser.Height < columnChooser.Columns.Count * 20)
        {
            columnChooser.ColumnChooserControl.ColumnChooserElement.Text = "";
        }
    }

    It is possible to add a contains filter. For this, you can add a textbox to the column chooser and filter the items when the text is changed:
    RadTextBox textbox = new RadTextBox();
    private void RadGridView1_ColumnChooserCreated(object sender, ColumnChooserCreatedEventArgs e)
    {
        e.ColumnChooser.Shown += ColumnChooser_Shown;
     
        if (!e.ColumnChooser.ColumnChooserControl.Controls.Contains(textbox))
        {
            textbox.Size = new Size(220, 20);
            textbox.TextChanged -= Textbox_TextChanged;
            textbox.TextChanged += Textbox_TextChanged;
            e.ColumnChooser.ColumnChooserControl.ColumnChooserElement.Margin = new Padding(1, 22, 1, 1);
            e.ColumnChooser.ColumnChooserControl.Controls.Add(textbox);
        }
    }
     
    private void Textbox_TextChanged(object sender, EventArgs e)
    {
        var columnChooser = radGridView1.ColumnChooser.ColumnChooserControl.ColumnChooserElement;
        columnChooser.UpdateView();
        foreach (ColumnChooserItem item in columnChooser.ElementsHolder.Children.ToList())
        {
            if (!item.Text.Contains(textbox.Text))
            {
     
                columnChooser.ElementsHolder.Children.Remove(item);
            }
        }
    }

    We will consider adding this functionality if we receive more request for it.

    I hope this will be useful.

    Regards,
    Dimitar
    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 WinForms is Visual Studio 2017 Ready
  4. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 03 Feb in reply to Dimitar Link to this post

    Thanks Dimitar,

    RadElementCollection has no ToList() Method, is there an extension method to be included?

    Regards

    Erwin

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 04 Feb Link to this post

    Hello Erwin,

    Thank you for writing back.

    ToList is a method of IEnumareble and it is available in .NET 4.0: Enumerable.ToList(TSource) Method (System.Linq)

    Instead, you can manually create a list of the items that should be removed:
    var itemsToRemove = new  List<ColumnChooserItem>();  
     
    foreach (ColumnChooserItem item in columnChooser.ElementsHolder.Children)
    {
        if (!item.Text.Contains(textbox.Text))
        {
            itemsToRemove.Add(item);
        }
    }
     
    foreach (var item in itemsToRemove)
    {
        columnChooser.ElementsHolder.Children.Remove(item);
    }

    Please let me know if there is something else I can help you with. 
     
    Regards,
    Dimitar
    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
  6. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 04 Feb in reply to Dimitar Link to this post

    Thanks, Dimitar.

    I have no dependency on Linq in this project , therefore the Extension Method not available.

    The example code works well as long as the column visibility is not changed (for example by clicking Hide in context Menu of the Grid).

    My users are a little confused how to use the column chooser, what I would like is a column chooser that resembles the one in MS Office products (for example Outlook).

     

     

     

    Kind Regards

     

     


     
  7. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 05 Feb Link to this post

    Hello Erwin,

    Thank you for writing back.

    I am not sure how to reproduce the case where this is not working. This is why I would like to kindly ask you to provide me with the exact steps that I need to take in order to reproduce the issue on my end. 
    Once I am able to do that, I will be able to investigate it and provide you with a solution. 

    In order to replicate the Field Chooser (see attached image) from Outlook, you can change the text box with a RadDropDownList and when an item is selected show specific columns only (for example use the SelectedIndexChanged event to filter the items according to the selected item). 

    I am looking forward to your reply.

    Regards,
    Dimitar
    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready