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

Show/Hide Filter in RadGrid

13 Answers 2290 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ban
Top achievements
Rank 1
Ban asked on 08 Feb 2009, 01:23 PM
Hi,
In my project I used RadGrid and I made the Filter Row appearance optional between Show and Hide, I put a "LinkButton" control in "CommanditemTemplate" tag in my Grid and on the "OnClick" event I call a code behind procedure including below statement to switch between the two state  :

RadGrid1.AllowFilteringByColumn = !RadGrid1.AllowFilteringByColumn;

My default state is Hide the Filter row but when I click my LinkButton the first click did not show the filter but the second click show it !! Why this happened !!! why its start to work with the second click only,
I try to solve it by JavaScript and the same problem appear to me,
Please help and advice me.
Thanks

Ban


 

 

13 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Feb 2009, 04:20 AM
Hello Ban,

Try rebinding the grid after showing/hiding the filter item on the button click event as shown below and see if it helps:
cs:
protected void LinkButton_Click(object sender, EventArgs e) 
    { 
        RadGrid1.AllowFilteringByColumn = !RadGrid1.AllowFilteringByColumn; 
        RadGrid1.Rebind(); 
    } 

Thanks
Princy.
0
Ban
Top achievements
Rank 1
answered on 09 Feb 2009, 08:43 AM
Hi Princy,
Thank you very much its working.

Thanks again
Ban
0
Luai
Top achievements
Rank 1
answered on 09 Mar 2009, 05:40 PM
Hello there,

I am doing the exact same thing only mine breaks the page.

When I allow the AllowFilteringByColumn from the aspx page on the mastertable it works fine.

However if I control it from code behind, when one clicks on the individual column filters instead of the dropdown menu the menu shows as lists of text on the top of the page.

I think it broke after i switched to Q3.
0
Sebastian
Telerik team
answered on 09 Mar 2009, 05:57 PM
Hi luay,

Can you please check whether the issue appears with the latest build available from your account? You may also check with IE developer toolbar or FireBug what the reason for the filtering menu to be positioned in a different location on the page is.

Let us know what your findings are.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Luai
Top achievements
Rank 1
answered on 09 Mar 2009, 06:28 PM

So basically I see  the menu as text links at top left of the browser without the styled menu.

In firebug the wrapping Div with the Ul with their css look like the following:
<!--<div class="RadMenu RadMenu_Web20 rmContextMenu RadMenu_Web20_Context" style="overflow: hidden; display: block; visibility: visible; z-index: 7000; left: 230px; top: 211px; height: 238px; width: 166px;">
  <ul class="rmActive rmVertical rmGroup rmLevel1" style="float: left; display: block; visibility: visible; top: 0px;">
   <li class="rmItem rmFirst"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">NoFilter</span></a></li><li class="rmItem"><a class="rmLink rmFocused" href="#" style="width: 126px;"><span class="rmText">Contains</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">DoesNotContain</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">StartsWith</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">EndsWith</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">EqualTo</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">NotEqualTo</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">GreaterThan</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">LessThan</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">GreaterThanOrEqualTo</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">LessThanOrEqualTo</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">Between</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">NotBetween</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">IsEmpty</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">NotIsEmpty</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">IsNull</span></a></li><li class="rmItem"><a class="rmLink" href="#" style="width: 126px;"><span class="rmText">NotIsNull</span></a></li><li class="rmItem rmLast" style="margin: 0px; padding: 0px; overflow: hidden; height: 0px;"><a class="rmLink" href="#" style="width: 126px; display: none;"><span class="rmText">Custom</span></a></li>
  </ul>
 </div>-->

0
Sebastian
Telerik team
answered on 10 Mar 2009, 08:09 AM
Hi luay,

Is there any AJAX involved when you encountered this issue? Does setting the EnableAjaxSkinRendering property of the grid to true alleviates the abnormality? If the problem persists, I will appreciate if you provide a live url where the discrepancy can be investigated further.

Regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Luai
Top achievements
Rank 1
answered on 10 Mar 2009, 02:33 PM
yes I am using the rad ajax manager.
I tried setting : EnableAjaxSkinRendering="true" . It was already set that way by default anyway.But the CSS doesn't get rendered properly.

To Isolate:
I created a new project that only has the radgrid and ajax manager using Q# as a reference and it works fine. Which makes me think that there is a something in my overall project that stops the proper rendering of that specific element's css.

For now I set the AllowFilteringByColumn="true", which makes the filterMenu work the way it is supposed to but I really wanted to hide the filter columns when it is not a postback.

Sorry but I can't post a live URL.

But here is the same exact simplified Code i have, this works fine by itself only breaks when integrated with my project.

ASPX page.......

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RadGridFiltering._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Rad grid With Filter</title>
    <style>
        .CommandItem
        {
            width: 100%;
        }
        .CommandItemLeft
        {
            float: left;
            text-align: left;
            padding: 0px 0.5em 0px 0px;
        }
        .CommandItemRight
        {
            float: right;
            text-align: right;
            padding: 0px 0px 0px 0.5em;
        }
        .Header_
        {
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div id="headerTitle" runat="server" align="center">
        <asp:Label ID="lblHeader" class="Header_" runat="server" Text="Rad grid With Filter"
            align="center" Style="color: #2f7eb5" Font-Bold="True" Font-Size="X-Large"></asp:Label>
    </div>
    <telerik:RadGrid ID="RadGrid_" runat="server" AllowSorting="True" AllowPaging="True"
        OnNeedDataSource="Table_OnNeedDataSource" Skin="Web20" EnableLinqExpressions="False"
        Width="100%" AutoGenerateColumns="False">
        <HeaderContextMenu Skin="Web20" EnableTheming="True">
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
        </HeaderContextMenu>
        <PagerStyle Mode="NextPrevNumericAndAdvanced" Font-Bold="False" Font-Italic="False"
            Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Wrap="True"
            AlwaysVisible="true" />
        <MasterTableView CommandItemDisplay="Top" AllowMultiColumnSorting="true" Width="100%">
            <NoRecordsTemplate>
                <asp:Label ID="NoRecords" runat="server" Text="There are no records to display at this time." />
            </NoRecordsTemplate>
            <CommandItemTemplate>
                <div class="CommandItem">
                    <div class="CommandItemRight">
                        <asp:LinkButton CssClass="CommandItemRefreshButton" ID="ToggleFiltering" runat="server"
                            CommandName="Toggle" OnClick="Toggle_Clicked">Toggle Filtering</asp:LinkButton>
                    </div>
                </div>
            </CommandItemTemplate>
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <%--<Columns>
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="ClientNetworkName" HeaderText="ClientNetworkName" DataField="ClientNetworkName"
                    UniqueName="ClientNetworkName" />
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="ClientEntryShare" HeaderText="ClientEntryShare" DataField="ClientEntryShare"
                    UniqueName="ClientEntryShare" />
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="BrowsingRelativePath" HeaderText="BrowsingRelativePath" DataField="BrowsingRelativePath"
                    UniqueName="BrowsingRelativePath" />
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="TargetNetworkName" HeaderText="TargetNetworkName" DataField="TargetNetworkName"
                    UniqueName="TargetNetworkName" />
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="TargetEntryShare" HeaderText="TargetEntryShare" DataField="TargetEntryShare"
                    UniqueName="TargetEntryShare" />
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="RedirectionRelativePath" HeaderText="RedirectionRelativePath"
                    DataField="RedirectionRelativePath" UniqueName="RedirectionRelativePath" />
            </Columns>--%>
            <Columns>
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="Column1_" HeaderText="Column1_" DataField="Column1" UniqueName="Column1_" />
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="Column2_" HeaderText="Column2_" DataField="Column2" UniqueName="Column2_" />
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="Column3_" HeaderText="Column3_" DataField="Column3" UniqueName="Column3_" />
                <telerik:GridBoundColumn CurrentFilterFunction="Contains" AutoPostBackOnFilter="true"
                    SortExpression="Column4_" HeaderText="Column4_" DataField="Column4" UniqueName="Column4_" />
            </Columns>
            <EditFormSettings>
                <PopUpSettings ScrollBars="None"></PopUpSettings>
            </EditFormSettings>
        </MasterTableView>
        <FilterMenu Skin="Web20" EnableTheming="True">
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
        </FilterMenu>
    </telerik:RadGrid>
    <telerik:RadAjaxManager ID="RadAjaxManager_" runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid_">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid_" LoadingPanelID="AjaxLoadingPanel" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="AjaxLoadingPanel" runat="server" Transparency="10"
        Height="80px" Width="80px" class="RadAjaxLoadingPanel">
        <div class="LoadingPanel">
            <div class="AlignCenter">
                <asp:Label ID="LoadingPanelLoadingLabel" runat="server" Text="Loading..." />
            </div>
        </div>
    </telerik:RadAjaxLoadingPanel>
    </form>
</body>
</html>

Code behind in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;

namespace RadGridFiltering
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Table_OnNeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            DataTable dataTable = new DataTable("Table");

            dataTable.Columns.Add("Column1");
            dataTable.Columns.Add("Column2");
            dataTable.Columns.Add("Column3");
            dataTable.Columns.Add("Column4");

            dataTable.Rows.Add(1, 2, 3, 4);
            dataTable.Rows.Add(1, 2, 3, 4);
            dataTable.Rows.Add(1, 2, 3, 4);
            dataTable.Rows.Add(1, 2, 3, 4);

            (source as RadGrid).DataSource = dataTable;
        }
        protected void Toggle_Clicked(object sender, EventArgs e)
        {
          
                int i = 0;
                foreach (var columns in RadGrid_.MasterTableView.Columns)
                {
                    if (RadGrid_.MasterTableView.Columns.Count < i)
                    {
                        i = 0;
                    }
                    if ((RadGrid_.MasterTableView.Columns[i] != null))
                    {
                        if (!RadGrid_.MasterTableView.Columns[i].Equals(""))
                        {
                            RadGrid_.MasterTableView.Columns[i].CurrentFilterValue = "";
                        }
                    }

                    i++;
                }
                RadGrid_.AllowFilteringByColumn = !(RadGrid_.AllowFilteringByColumn);
                RadGrid_.Rebind();
        }
    }
}

0
Sebastian
Telerik team
answered on 13 Mar 2009, 11:35 AM

Hi luay,

Thank you for the code snippets.

Can you check whether showing/hiding the filter item in the grid on the client (using the showFilterItem()/hideFilterItem() methods from its client-side API as in this demo) alleviates the discrepancy with the styles/filter menu positioning? Note that you can invoke these methods intercepting the OnGridCreated client event (for example).

I also noticed that you set custom styles for your command item with float/padding - does removing them temporary produces different result?

Kind regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mahesh Babu
Top achievements
Rank 1
answered on 23 Jul 2009, 05:19 AM
I am also facing the same issue. I have a radgrid with two radio buttons ON and OFF to swicth on/off the radgrid column filtering. This works perfectly when I use autopostbacks on radio buttons. But the filter menu is displayed as text on page when i keep radio buttons in RadAjaxManager to update radgrid. please let me know any workaround to this.
0
Sebastian
Telerik team
answered on 23 Jul 2009, 08:54 AM
Hello Mahesh,

Can you please check whether setting the EnableAjaxSkinRendering property of the RadGrid filtering menu to true addresses the issue with the filter menu styling? This can be done inside the OnInit handler of the grid (see this example to see how to reference the menu in the handler).

Additionally, verify that you are using the latest release 2009.2.701 of RadControls for ASP.NET AJAX.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ilber
Top achievements
Rank 1
answered on 30 Nov 2009, 12:59 PM
Hi you all,

I have a similar problem. This is my Grid:

<telerik:RadGrid ID="dgDocuments" runat="server" Skin="Office2007" 
                                         OnNeedDataSource="dgDocuments_NeedDataSource"  
                                         OnItemCreated="dgDocuments_ItemCreated"  
                                         ShowGroupPanel="true" ShowStatusBar="true"  >  
                             
                            <MasterTableView DataKeyNames="ID" AllowFilteringByColumn="true" AllowSorting="true" 
                                             PageSize="20" AutoGenerateColumns="false" GridLines="none" AllowPaging="true" 
                                             Font-Size="X-Small" > 
                            </MasterTableView> 
                             
                            <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True"
                            </ClientSettings> 
                            <GroupingSettings ShowUnGroupButton="True" /> 
                            <ItemStyle Font-Size="X-Small"  BackColor="AliceBlue" /> 
                            <HeaderStyle Font-Size="Smaller" /> 
                             
                             
                            <AlternatingItemStyle Font-Size="X-Small" BackColor="Lavender" BorderColor="Transparent" /> 
    </telerik:RadGrid> 

I fill the grid after the click on a Radtreeview. When i click on the Filter icon in all the columns instead of the dropdown menu the menu shows as lists of text on the top of the page.

this only appears when i use Ajax Manager:
 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" > 
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="trvArchivi"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="dgDocuments" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager> 

If i don't use Ajax Manager eveything goes well..

Can anybody tell me where is the problem.

Thanks

0
Ilber
Top achievements
Rank 1
answered on 01 Dec 2009, 11:35 AM
Hey....

Can someone help me please!!!
0
Michael
Top achievements
Rank 1
answered on 08 Dec 2011, 03:52 PM
Id like to add that i recently had an issue with two rad grids on a single page.  The first issue was the filter rows not showing on the first click but also the two filters on the grids would open and close each other randomly (even though the events were different and firing differently). Adding a Rebind() after the toggle fixed it.

Hope this helps future people. 

Regards
Michael
Tags
Grid
Asked by
Ban
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ban
Top achievements
Rank 1
Luai
Top achievements
Rank 1
Sebastian
Telerik team
Mahesh Babu
Top achievements
Rank 1
Ilber
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or