Hide certain flter menu options in RadFilter

7 posts, 0 answers
  1. Raji
    Raji avatar
    56 posts
    Member since:
    Jul 2011

    Posted 26 Jul 2011 Link to this post

    Hi,

    I am using the RadGrid with RadFilter. I wanted to show only certain flter menu options. I found a code in the documentation and tried but I am getting an error 'findItemByValue(...) ' is null or not an object. The code is shown below. Does anyone have the same problems.

     

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

     

     

    <script type="text/javascript">

     

    function pageLoad(sender, args)

     

    {

     

    var filter = $find("<%=RadFilter1.ClientID %>");

     

     

    var menu = filter.get_contextMenu();

     

    menu.add_showing(FilterMenuShowing);

    }

     

    function FilterMenuShowing(sender, args)

     

    {

     

    var filter = $find("<%=RadFilter1.ClientID%>");

     

     

    var currentExpandedItem = sender.get_attributes()._data.ItemHierarchyIndex;

     

     

    var fieldName = filter._expressionItems[currentExpandedItem];

     

     

    var allFields = filter._dataFields;

     

     

    var dataType = null;

     

     

    for (var i = 0, j = allFields.length; i < j; i++)

     

    {

     

    if (allFields[i].FieldName == fieldName)

     

    {

    dataType = allFields[i].DataType;

     

    break;

     

    }

    }

     

     

    switch (dataType)

     

    {

     

    case "System.Int32":

     

    sender.findItemByValue(

    "NotEqualTo").set_visible(false);

     

    sender.findItemByValue(

    "Between").set_visible(false);

     

    sender.findItemByValue(

    "NoBetween").set_visible(false);

     

    sender.findItemByValue(

    "IsNull").set_visible(false);

     

    sender.findItemByValue(

    "NotIsNull").set_visible(false);

     

     

    break;

     

     

    case "System.String":

     

    sender.findItemByValue(

    "DoesNotContain").set_visible(false);

     

    sender.findItemByValue(

    "NotEqualTo").set_visible(false);

     

    sender.findItemByValue(

    "GreaterThan").set_visible(false);

     

    sender.findItemByValue(

    "LeassThan").set_visible(false);

     

    sender.findItemByValue(

    "GreaterThanOrEqualTo").set_visible(false);

     

     

    break;

     

     

    case "System.DateTime":

     

    sender.findItemByValue(

    "NotEqualTo").set_visible(false);

     

    sender.findItemByValue(

    "Between").set_visible(false);

     

    sender.findItemByValue(

    "NoBetween").set_visible(false);

     

    sender.findItemByValue(

    "IsNull").set_visible(false);

     

    sender.findItemByValue(

    "NotIsNull").set_visible(false);

     

     

    break;

     

    }

    }

     

    </

     

    script>

     

     

     

     

     

     

     

    </telerik:RadCodeBlock>

     

  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 27 Jul 2011 Link to this post

    Hi Raji,

    Attached to this message is a sample working project which demonstrates how you can achieve the desired functionality. Please give it a try and let me know if it works for you.

    Best wishes,
    Pavlina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Raji
    Raji avatar
    56 posts
    Member since:
    Jul 2011

    Posted 27 Jul 2011 Link to this post

    Hi Pavlina,

    I am developing in Vs2005 and .net 2.0. I am using the following dll versions
    Telerik.Web.Design.dll(2010.3.1317.20)
    Telerik.Web.UI.dll(2010.3.1317.20)

    When I tried to use the same code I get the following javascript error 'this._contextMenu is null or not an object'

    below is my code.

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomRadFilterRadGrid.aspx.cs" Inherits="CustomRadFilterRadGrid" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
    <head runat="server">
        <title>Untitled Page</title>
        <link rel="STYLESHEET" href="StyleSheet/Grid_ECMS.css" type="text/css" />  
        <link rel="STYLESHEET" href="StyleSheet/ComboBox_ECMS.css" type="text/css" />    
        <style type="text/css">
            .filterDiv
            {
                margin: 20px 0px 10px 0px;
            }
            .GridRowOver_ECMS td 
            
                background-color: red; 
                cursor:pointer; 
            
           /** .RadComboBoxDropDown_ECMS
           {
               background-color: Red !important;
           }**/
      
      
        </style>
        
    </head>
    <body>
    <form id="form1" runat="server">
        <div>
            <!-- content start -->
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
            <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadFilter1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadFilter1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
            <div class="filterDiv">
                <telerik:RadFilter runat="server" ID="RadFilter1" ShowApplyButton="false" OnApplyExpressions="RadFilter1_ApplyExpressions" onitemcommand="RadFilter1_ItemCommand">
                     <FieldEditors>
                        <telerik:RadFilterTextFieldEditor FieldName="OrderID" DataType="System.Int32" />
                        <telerik:RadFilterTextFieldEditor FieldName="ShipName" DataType="System.String" />
                        <telerik:RadFilterDateFieldEditor FieldName="OrderDate" DataType="System.DateTime" />
                    </FieldEditors>
                    <ClientSettings>
                        <ClientEvents OnFilterCreated="FilterCreated" />
                    </ClientSettings>
                </telerik:RadFilter>
            </div>
            <telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
                AllowPaging="true" AllowSorting="true" AllowFilteringByColumn="true" OnItemCommand="RadGrid1_ItemCommand" 
                OnItemCreated="RadGrid1_ItemDataBound" Skin="ECMS" EnableEmbeddedSkins="false" ImagesPath="Grid">
                <MasterTableView IsFilterItemExpanded="False" CommandItemDisplay="Top" DataSourceID="SqlDataSource1">
                    <CommandItemTemplate>
                        <telerik:RadToolBar runat="server" ID="RadToolBar1" OnButtonClick="RadToolBar1_ButtonClick">
                            <Items>
                                <telerik:RadToolBarButton Text="Apply filter" CommandName="ApplyFilterRadGrid"/>
                                <telerik:RadToolBarButton Text="Clear filter" CommandName="ClearFilterRadGrid"/>
                            </Items>
                        </telerik:RadToolBar>
                    </CommandItemTemplate>
                    <Columns>
                        <telerik:GridTemplateColumn UniqueName="MyButtonColumn">
                            <ItemTemplate>
                                <asp:LinkButton  ID="btnTest" runat="server" Text="View"></asp:LinkButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn
                        <telerik:GridNumericColumn DataField="OrderID" HeaderText="OrderID" DataType="System.Int32" DecimalDigits="2" FilterControlAltText="Filter OrderID column" UniqueName="OrderID" />
                        <telerik:GridDateTimeColumn DataField="OrderDate" HeaderText="OrderDate" DataFormatString="{0:MM/dd/yyyy}" FilterControlAltText="Filter OrderDate column" UniqueName="OrderDate"/>
                        <telerik:GridNumericColumn DataField="ShipVia" HeaderText="ShipVia" DataType="System.Int32" DecimalDigits="2" FilterControlAltText="Filter ShipVia column" UniqueName="ShipVia" />
                        <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" FilterControlAltText="Filter ShipName column" UniqueName="ShipName" />
                        <telerik:GridBoundColumn DataField="ShipAddress" HeaderText="ShipAddress" FilterControlAltText="Filter ShipAddress column" UniqueName="ShipAddress" />
                        <telerik:GridNumericColumn DataField="Freight" HeaderText="Freight" DataType="System.Decimal" DecimalDigits="2" FilterControlAltText="Filter Freight column" UniqueName="Freight" />
                    </Columns>
                </MasterTableView>            
                <ClientSettings>
                    <Selecting AllowRowSelect="true" />                
                </ClientSettings>
            </telerik:RadGrid>
            <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                SelectCommand="Select OrderID, OrderDate, ShipVia, ShipName, ShipAddress, Freight FROM Orders" />
            <!-- content end -->
             
        </div>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                <script type="text/javascript">
                  
                 function testClick(rowIndex)
                 {
                 alert(rowIndex);
                 window["<%= RadGrid1.ClientID %>"].MasterTableView.SelectRow(window["<%= RadGrid1.ClientID %>"].MasterTableView.Rows[rowIndex].Control, true);
      
    function FilterCreated(sender, eventArgs) 
                    {
                        var filterMenu = sender.get_contextMenu();
                        filterMenu.add_showing(FilterMenuShowing);
                    }
                    function FilterMenuShowing(sender, args) 
                    {
                        var filter = $find("<%=RadFilter1.ClientID%>");
                        var currentExpandedItem = sender.get_attributes()._data.ItemHierarchyIndex;
                        var fieldName = filter._expressionItems[currentExpandedItem];
                        var allFields = filter._dataFields;
                        var dataType = null; 
                        for (var i = 0, j = allFields.length; i < j; i++) 
                        
                         alert(allFields[i].FieldName );
                            if (allFields[i].FieldName == fieldName) 
                            
                                dataType = allFields[i].DataType; 
                                alert(dataType);
                                break; 
                            
                        }
                          
                        switch (dataType) 
                        
                        case "System.Int32": 
                            sender.findItemByValue("NotEqualTo").set_visible(false);
                            sender.findItemByValue("Between").set_visible(false);
                            sender.findItemByValue("NoBetween").set_visible(false);
                            sender.findItemByValue("IsNull").set_visible(false);
                            sender.findItemByValue("NotIsNull").set_visible(false);
                            break;
                        case "System.String": 
                            sender.findItemByValue("DoesNotContain").set_visible(false);
                            sender.findItemByValue("NotEqualTo").set_visible(false);
                            sender.findItemByValue("GreaterThan").set_visible(false);
                            sender.findItemByValue("LeassThan").set_visible(false);
                            sender.findItemByValue("GreaterThanOrEqualTo").set_visible(false);
                            break;
                        case "System.DateTime": 
                            sender.findItemByValue("NotEqualTo").set_visible(false);
                            sender.findItemByValue("Between").set_visible(false);
                            sender.findItemByValue("NoBetween").set_visible(false);
                            sender.findItemByValue("IsNull").set_visible(false);
                            sender.findItemByValue("NotIsNull").set_visible(false);
                            break;
                     }
                    }                                  
                     
                </script>
                  
                 
            </telerik:RadCodeBlock>
      
        </form>
      
    </body>
    </html>

    Thanks,
    Raji
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 28 Jul 2011 Link to this post

    Hello Raji,

    I suggest that you examine the following forum thread which elaborates on this matter and let me know if it helps:
    http://www.telerik.com/community/forums/aspnet-ajax/filter/bug-exceptions-thrown-by-radfilter-on-operations-with-zero-operands.aspx 

    Best wishes,
    Pavlina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Raji
    Raji avatar
    56 posts
    Member since:
    Jul 2011

    Posted 28 Jul 2011 Link to this post

    Hi Pavlina,

    I compared the code sample that you had attached to this thread to my code and removed the following lines and then it started to work.
    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadFilter1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadFilter1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>

    I do not know whay the above lines is creating it not to work. I hope this may be useful to others who has the similar problem.

    I have another question related to the RadFilter. I am not sure if I need to create another thread for it. Here is my question. I have DateTime field(RadFilterDateFieldEditor) in my RadFilter. It works fine but I do not want the time to be displayed when I select a date. 

    Thanks,
    Raji
  7. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 29 Jul 2011 Link to this post

    Hi Raji,

    I hope that the forum thread below will be useful for you:
    http://www.telerik.com/community/forums/aspnet-ajax/filter/filtering-by-date-only-using-radfilter.aspx

    All the best,
    Pavlina
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  8. Raji
    Raji avatar
    56 posts
    Member since:
    Jul 2011

    Posted 29 Jul 2011 Link to this post

    Hi Pavlina,

    Thanks for sending me the link. I found another thread which I think may work for me.
    http://www.telerik.com/community/forums/aspnet-ajax/filter/radfilter-not-able-to-use-double-quote.aspx

    The problem with the code is that it is using the 'var' keyword and I am using .Net 2.0. Do you have alternative code that I can use in .net 2.0. I have posted a question under that thread.
     
    Thanks,
    Raji
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017