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

How do you hide filter options for a given column?

14 Answers 977 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hacheyj
Top achievements
Rank 2
hacheyj asked on 15 Mar 2008, 03:57 AM
Using:

<ClientSettings> 
   <ClientEvents OnFilterMenuShowing="filterMenushowing" /> 
</ClientSettings> 

How do I eliminate filter options for a given column under Prometheus.

I've gotten this far:

    <script type="text/javascript" language="javascript">  
      
      function filterMenushowing(sender, eventArgs)  
      {  
        if(eventArgs.get_column().get_uniqueName() == "unique_invoice_no")  
        {  
            var menu = eventArgs.get_menu();  
              
            var i = 0;  
            while (i < menu._items.length)  
            {  
                if (menu._items[i].Value != "NoFilter" && menu._items[i].Value != "EqualTo")  
                {  
                    ???     
                }  
                i++;  
            }  
              
        }  
      }  
        
    </script> 

But trying to set the style to display = "none" where the question marks are does nothing? Do we do something with currentStyle now? Something totally different?

14 Answers, 1 is accepted

Sort by
0
hacheyj
Top achievements
Rank 2
answered on 15 Mar 2008, 03:01 PM
Figured out how - not too different from the previous version:

In your RadGrid declaration, insert:

<ClientSettings> 
   <ClientEvents OnFilterMenuShowing="filterMenushowing" /> 
</ClientSettings> 

Then, create a Javascript function on the page:

<script type="text/javascript" language="javascript">  
      
      function filterMenushowing(sender, eventArgs)  
      {  
        if(eventArgs.get_column().get_uniqueName() == "unique_invoice_no")  
        {  
            var menu = eventArgs.get_menu();  
              
            var i = 0;  
            while (i < menu._items.length)  
            {  
                if (menu._items[i].Value != "NoFilter" && menu._items[i].Value != "EqualTo")  
                {  
                    $get(menu._items[i].id).style.display="none";  
                }  
                i++;  
            }  
              
        }  
      }  
        
</script> 

Substitute "unique_invoice_no" for whatever the unique name of your column is and alter the if statement according to the columns you want to show.

Is there any server-side way of doing this yet?
0
Sebastian
Telerik team
answered on 17 Mar 2008, 08:36 AM
Hello hacheyj,

How to reduce the filter menu options server-side you can learn from this documentation topic. Thank you for posting the client-side solution with the OnFilterMenuShowing event in this forum post - this other community members can benefit from it as well. I have updated your Telerik points for the involvement.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Markus
Top achievements
Rank 1
answered on 17 Apr 2008, 08:32 AM

Hi,

the above sample for removing filter options in the filter menu doesn't work anymore in the Q1 2008 Release. This is how I modified the clientscript to make it work again:

    <script type="text/javascript" language="javascript">    
            
        function filterMenushowing(sender, eventArgs)  
        {    
            if (eventArgs.get_column().get_uniqueName() == "unique_invoice_no")     
            {             
                var menu = eventArgs.get_menu();  
                var items = menu._itemData;  
 
                var i = 0;  
                while (i < items.length)    
                {    
                    if (items[i].value != "NoFilter" && items[i].value != "EqualTo")    
                    {    
                        var item = menu._findItemByValue(items[i].value);  
                        if (item != null)  
                            item._element.style.display="none";  
                    }    
                    i++;    
                }    
            }     
        }  
    </script> 

Again substitute "unique_invoice_no" with your unique column name or remove that condition if you want to modify the filter options of all of your columns.

This works fine for me. If there's a better way then please let me know.
0
Sebastian
Telerik team
answered on 17 Apr 2008, 10:40 AM
Hi Sebastian,

Thank you for posting your solution in this forum thread and notifying the Telerik community about the difference. I updated your Telerik points for the feedback.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
debbie f
Top achievements
Rank 1
answered on 01 Jul 2008, 07:36 PM
So is the only way to eliminate a filtermenu item per column is client-side?  I've implemented code for my grid using OnInit and removing all of the extraneous options we don't need.  However, I want GreaterThan as an option for columns of type int but not for a column of type string. 

The solution using OnInit for my grid is a global solution (which is great for most of the items I need to remove), but then I need to tweak the list a bit more based on column datatype.  I *think* it should be possible in the OnItemCreated event but can't seem to get it working correctly.
0
Sebastian
Telerik team
answered on 02 Jul 2008, 06:58 AM
Hello debbie f,

If you would like to remove some of the filter menu options for particular columns only, you need to intercept the OnFilterMenuShowing client event of the grid and consider the approach implemented by Jonathan/Sebastian in this forum thread. The server-side solution will remove the relevant items from all grid columns.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Sinan
Top achievements
Rank 1
answered on 23 Jul 2008, 10:10 AM
Hi.

I try to replace the filterMenuShowing method with mine. Because I changed it in my MasterPage and works fine, but I want the filterMenu to be different for a pecific page. In that page I wrote

<ClientSettings>
            <Scrolling AllowScroll="True"/>
            <ClientEvents  OnFilterMenuShowing="filterMenuShowingUyeList"/>
        </ClientSettings>

But when I look at the pages source I still see OnRowDeleted:"",OnFilterMenuShowing:"FilterMenuShowing"}

what can be the problem, is it a version problem. My dll version is 5.0.1.0
0
Sebastian
Telerik team
answered on 23 Jul 2008, 02:35 PM
Hi Sinan,

If you specify different handlers for the OnFilterMenuShowing event of each of your grids (residing in the content pages of your master page), there should be no problem handling the event separately for each control when it is raised clicking the filter menu icon in a grid column header.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jerry Jansen
Top achievements
Rank 1
answered on 19 Aug 2008, 06:19 PM
I am trying to limit the filter items for one of my columns using the client side code discussed in this thread. That works but once I click on the filter menu for the column, then all the other columns have their filter menu items reduced also.

Example: I have four columns, one is a date column, all others are text columns. I can click on any of the text columns and all filter menu items display. And when I click on the date column then only the five filter menu items display which is what I want. But, after clicking on the date column and then clicking on any of the text columns, now they all only display the five menu items on the date filter menu.

How can I have all the text columns again display all of the filter menu items after clicking on the date filter?
0
Nikita Gourme
Top achievements
Rank 1
answered on 22 Aug 2008, 01:13 PM
Jerry, if the custom condition for the unique name of the column is not met, no filter menu options should be hidden from the end user - I tested that myself. To trace the reason for the issue with your implementation, debug the code to see whether the conditional block is entered when you perform the actions you depicted.

Nikita
0
golddog
Top achievements
Rank 1
answered on 02 Sep 2008, 04:24 PM
Jerry, I had the same problem following the client-side example.  I finally came to the conclusion that it was due to the one column setting display = none, and that setting being maintained across columns.

Where you're setting display = none, try adding an else and setting

item._element.style.display = '';

on the ones you want to show.  That seemed to work for me to allow different sets per column when clicking around the filters.
0
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 07 Jun 2011, 05:48 PM

Just to bump this topic... I implemented my own version of the solution using an Array utility function I have in my own javascript library. It works like a charm:

if (!Array.prototype.contains){
        Array.prototype.contains = function(obj){
    var len = this.length;
    for (var i = 0; i < len; i++){
      if(this[i]===obj){ return true;}
    }
    return false;
  };
}
  
function FilterMenuShowingHandler(sender, eventArgs)   
        {   
            var colName = eventArgs.get_column().get_uniqueName();
            var menu = eventArgs.get_menu();
              
            var items = menu._itemData;
              
            switch (colName) {
              
                case "myColumnName":
                    var i = 0;
                    while (i < items.length) {
                        var arrMenuOptions = ['NoFilter', 'Contains', 'DoesNotContain', 'StartsWith', 'EndsWith', 'EqualTo', ' NotEqualTo'];
                        if (!arrMenuOptions.contains(items[i].value)) {
                            var item = menu._findItemByValue(items[i].value);
                            if (item) {
                                item._element.style.display = "none";
                            }
                        }
                        i++;
                    }
                    break;
  
            }     
  
  
        }


However, I have a few comments on the solution:

1) In certain situations where I have more than one text column being filtered, I too have the issue with having to set style.display='' for those items I want to be visible so that my hiding of items is not copied across menus. This works, but it sure adds more complexity. It would be better if the items would be shown by default as Nikita suggested, but that is not the case.

2) Its great and powerful that telerik exposes events like FilterMenuShowing which allow developers to really dig in and access various aspects of the control client-side. However, solutions like the one provided here tend to be pretty fragile in the long run. This thread includes an example of where the handler had to be rewritten because it no longer worked under a new version of the controls. Telerik is great about constantly looking for ways to improve the functionality and performance of its controls. However, this means that breaking changes occur more often than one would like as a developer. When it comes to Telerirk providing specialized client-side solutions for obscure functionality requirements, I think there's an acceptance that the solution may not be completely future-proof. However, the ability to provide unique and custom filter menus for different columns is not an obscure functionality requirement. In fact, its a pretty basic requirement of any full-fledged grid filtering interface. This fuctionality should be built in to the control and manifested as a property of the column (FilterMenuOptions="NoFilter, StartsWith, Contains" for instance). Its been more than two years since this thread was started and to my knowledge no such built-in solution exists. Now, I know Telerik traditionally builds new functionality based on developer interest and I have no idea to what extent such built-in functionality as I describe here has been requested. However, I'm pretty sure Telerik didn't poll developer interest when they decided to make their grid sortable, or page-able. Those are expected functionalities of any grid. While filtering is a little more advanced and an example of Telerik's excellence, this issue of custom filtering options is pretty standard and IMO, should be built-in without having to go through a voting process, particularly since it has been years since fitering was first introduced in RadGrid. Anyhow, I'm hoping Teleirk is working on such a solution for the next RadGrid Update. The flexibility and customizabilty of Telerik's API is fantastic and is what sets Telerik apart from its competitors. But having to implement fragile solutions to what seems like standard functionality can become frustrating.
0
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
answered on 05 Feb 2013, 01:36 PM
Has there been any movement on making the limiting of filter options in the grid filter menu a built in property as opposed to a fragile and cumbersome event handler?
0
Maria Ilieva
Telerik team
answered on 08 Feb 2013, 10:47 AM
Hi Albert,

The required functionality is not implemented as a inbuilt feature of the RadGrid control and currently we do not plan to do so.
The possible approach for achieving the required behavior strays the one describe dint he help topic below:
http://www.telerik.com/help/aspnet-ajax/grid-reducing-filtermenu-options.html


Kind regards,
Maria Ilieva
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
hacheyj
Top achievements
Rank 2
Answers by
hacheyj
Top achievements
Rank 2
Sebastian
Telerik team
Markus
Top achievements
Rank 1
debbie f
Top achievements
Rank 1
Sinan
Top achievements
Rank 1
Jerry Jansen
Top achievements
Rank 1
Nikita Gourme
Top achievements
Rank 1
golddog
Top achievements
Rank 1
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Maria Ilieva
Telerik team
Share this question
or