Hidding/Collapsing FilterButton on some columns

2 Answers 46 Views
GridView
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Mark asked on 24 Jan 2024, 09:51 PM

When I Hide/Collapse the FILTER button in the column header, it doesn't remove the space from the header until the user clicks in the row/header.  I must be doing something wrong. Currently, I am using the ViewCellFormatting event to hide/collapse the FilterButton. 

 

Any ideas?

 

Thanks.

2 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 26 Jan 2024, 07:56 AM

Hello Mark,

I am assuming that Excel-like filtering is enabled. If you want to disable the filter option of a specific column, you can set the AllowFiltering property of the column to false. You can get the required column from the Columns collection. Keep in mind that the Columns collection will be populated after the DataSource property is set.

this.radGridView1.EnableFiltering = true;
this.radGridView1.MasterTemplate.ShowHeaderCellButtons = true;
this.radGridView1.MasterTemplate.ShowFilteringRow = false;
this.radGridView1.DataSource = items;
this.radGridView1.Columns[1].AllowFiltering = false;

Here is the result:

Can you give this approach a try and let me know if it works for you?

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 26 Jan 2024, 12:44 PM

Okay, you gave me something to look at and I think I found the problem, but I am having a hard time repoing it in an example, but in my application, moving the HeaderTextAlignment = ContentAlignment.MiddleRight before you set AllowFiltering = false on the column fixed my problem.

Thanks for at least pointing me in the right direction to figure this out.

 

I will keep trying to make my sample project do what my application is doing and then I will submit it.

0
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
answered on 28 Feb 2024, 08:08 PM

So, after more research, I added the following event to my abstract class of my RadGridView


      private void myRadGridView_ViewCellFormatting(object sender, CellFormattingEventArgs e)
      {
         if (e.CellElement is GridHeaderCellElement { ColumnInfo: GridViewDataColumn gvColumn } ghCellElement)
         {
            if (!gvColumn.AllowFiltering)
            {
               ghCellElement.FilterButton.Visibility = ElementVisibility.Collapsed;
            }
            else
            {
               ghCellElement.FilterButton.Visibility = ElementVisibility.Visible;
            }
         }
      }

Dinko | Tech Support Engineer
Telerik team
commented on 29 Feb 2024, 03:27 PM

Thank you for sharing your approach. If I have correctly understood, you have found a solution for your case. Let me know if I am wrong.

If you have any other questions, feel free to open new thread and we will be happy to help.

Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
commented on 29 Feb 2024, 06:28 PM

Yes, I found a solution.   I just find it weird, that if a column is not filterable, why the control would remain, IMO, this should be internally collapsed as soon as the AllowFilter on the column is set to FALSE.
Tags
GridView
Asked by
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Answers by
Dinko | Tech Support Engineer
Telerik team
Mark
Top achievements
Rank 2
Bronze
Bronze
Veteran
Share this question
or