Radgrid filters not working properly

7 posts, 1 answers
  1. Manishkumar
    Manishkumar avatar
    240 posts
    Member since:
    Feb 2009

    Posted 22 Sep 2011 Link to this post

    hi,
    I am using the following code in aspx.cs and aspx page to turn off/on the filetring of radgrid, but its working in reverse. When I click on FilterOn button, filters hide and when I click on FilterOff button, filters show up..it should not work like that

    protected void btnFilterOn_Click(object sender, EventArgs e) 
            rdgResult.MasterTableView.TableLayout = GridTableLayout.Auto; 
            rdgResult.AllowFilteringByColumn = true; 
            rdgResult.MasterTableView.AllowFilteringByColumn = true; 
            hdnFilterState.Value = "ON"
            this.BindGrid(); 
            ibtnFilterOff.Visible = true; 
            ibtnFilterOn.Visible = false; 
            btnFilterOnBtm.Visible = false; 
            btnFilterOffBtm.Visible = true; 
            
    protected void btnFilterOff_Click(object sender, EventArgs e) 
           rdgResult.MasterTableView.TableLayout = GridTableLayout.Auto; 
            rdgResult.AllowFilteringByColumn = false; 
            rdgResult.MasterTableView.AllowFilteringByColumn = false; 
            hdnFilterState.Value = "OFF"
            this.BindGrid(); 
            ibtnFilterOff.Visible = false; 
            ibtnFilterOn.Visible = true; 
            btnFilterOnBtm.Visible = true; 
            btnFilterOffBtm.Visible = false;
     }

    telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel"> 
                                        <AjaxSettings
                                            <telerik:AjaxSetting AjaxControlID="rdgResult"
                                                <UpdatedControls
                                                    <telerik:AjaxUpdatedControl ControlID="rdgResult" /> 
                                                </UpdatedControls
                                            </telerik:AjaxSetting
                                        </AjaxSettings
    </telerik:RadAjaxManager
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel" runat="server" Transparency="50"
                                        <img alt="Loading..." src="Images/Loading.gif" style="border: 0px; margin-top: 60px;" /> 
    </telerik:RadAjaxLoadingPanel
        
    <telerik:RadGrid ID="rdgResult" runat="server" Skin="Office2007" Width="957px" BackColor="White"
                                            AutoGenerateColumns="true" PageSize="10" AllowSorting="True" AllowPaging="True"
                                            filtercontrolwidth="5px" AllowFilteringByColumn="false" showfiltericon="true"
                                            filterlistoptions="VaryByDataType" showsorticon="true" EnableViewState="true"
                                            ClientSettings-Scrolling-AllowScroll="true" OnNeedDataSource="rdgResult_NeedDataSource"
                                            OnItemDataBound="rdgResult_ItemDataBound" OnColumnCreated="rdgResult_ColumnCreated"
                                            OnItemCreated="rdgResult_ItemCreated" OnDetailTableDataBind="rdgResult_DetailTableDataBind"
                                            OnExcelMLExportRowCreated="rdgResult_ExcelMLExportRowCreated" OnExcelMLExportStylesCreated="rdgResult_ExcelMLExportStylesCreated"
                                            OnPreRender="rdgResult_PreRender"
                                            <HeaderStyle Width="160px" HorizontalAlign="Center" CssClass="clsTableHeading1" /> 
                                            <ItemStyle Font-Size="8pt" HorizontalAlign="Left" CssClass="clsTableCellLeft" /> 
                                            <ExportSettings FileName="Detail Report" IgnorePaging="true" Excel-Format="ExcelML" /> 
                                            <ClientSettings EnableRowHoverStyle="false"
                                                <Selecting AllowRowSelect="false" EnableDragToSelectRows="false" /> 
                                                <Scrolling AllowScroll="false" UseStaticHeaders="true" ScrollHeight="100"/> 
                                            </ClientSettings
                                            <MasterTableView TableLayout="Auto" Name="DetailRpt" Width="100%" Height="90%" AllowMultiColumnSorting="false"
                                                DataKeyNames="Document #" HierarchyLoadMode="ServerOnDemand" HeaderStyle-Font-Bold="true"
                                                HeaderStyle-HorizontalAlign="Center" AllowFilteringByColumn="false" ItemStyle-HorizontalAlign="Left"
                                                <%-- <HeaderStyle Width="200px" />--%> 
                                                <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric"></PagerStyle
                                                <NoRecordsTemplate
                                                    <span class="clsTableCellCenter" style="padding-left: 250px;"><b>Sorry, there is no 
                                                        matching data available for display.</b></span
                                                </NoRecordsTemplate
                                                <Columns
                                                    <telerik:GridTemplateColumn HeaderStyle-Width="30px" HeaderText="Sel" ShowFilterIcon="false"
                                                        DataField="column value" HeaderStyle-HorizontalAlign="Center" AllowFiltering="false"
                                                        ItemStyle-HorizontalAlign="Center"
                                                        <ItemTemplate
                                                            <asp:Literal ID="RadioButtonMarkup" runat="server" EnableViewState="true"></asp:Literal
                                                                                        <input type="hidden" id="hdnDocNo" name="hdnDocNo" runat="server" value='<%# DataBinder.Eval(Container.DataItem,"Document #")%>' /> 
                                                            <input type="hidden" id="hdnRevision" name="hdnRevision" runat="server" value='<%# DataBinder.Eval(Container.DataItem,"Rev Ltr")%>' /> 
                                                            <input type="hidden" id="hdnFlag" name="hdnFlag" runat="server" value='<%# DataBinder.Eval(Container.DataItem,"SHOWHYPERLINK")%>' /> 
                                                            <input type="hidden" id="hdnStatus" name="hdnStatus" runat="server" value='<%# DataBinder.Eval(Container.DataItem,"STATUS")%>' /> 
                                                        </ItemTemplate
                                                    </telerik:GridTemplateColumn
                                                </Columns
                                                  
                                            </MasterTableView
                                        </telerik:RadGrid>

    Thanks in Advance.
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Sep 2011 Link to this post

    Hello Manish,

    Can you try  rebinding the grid instead of calling the BindGrid method. Here is a sample code which worked as expected.
    aspx:
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AutoGenerateColumns="true" Width="97%" OnNeedDataSource="RadGrid1_NeedDataSource" AllowFilteringByColumn="true">
       <MasterTableView CommandItemDisplay="Top" UseAllDataFields="true">
    </telerik:RadGrid>
    <asp:Button ID="Button2" runat="server" Text="FilterOn" onclick="Button2_Click1" />
    <asp:Button ID="Button3" runat="server" Text="FilterOff" onclick="Button3_Click1" />
    C#:
    class Employee
    {
        private int _Id;
        private string _Name;
        public int EmpId
        {
            get { return _Id; }
            set { _Id = value; }
        }
        public string FName
        {
            get { return _Name; }
            set { _Name = value; }
        }
    }
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            SetGridDataSource();
        }
        public void SetGridDataSource()
        {
            RadGrid1.DataSource = GetList();
        }
        private List<Employee> GetList()
        {
            List<Employee> employees = new List<Employee>();
            for (int i = 0; i < 10; i++)
            {
                Employee emp = new Employee();
                emp.EmpId = 100;
                emp.FName = "John";
                employees.Add(emp);
            }
            return employees;
        }
     
     protected void Button2_Click1(object sender, EventArgs e)
        {
            RadGrid1.MasterTableView.TableLayout = GridTableLayout.Auto;
            RadGrid1.AllowFilteringByColumn = true;
            RadGrid1.MasterTableView.AllowFilteringByColumn = true;
            RadGrid1.Rebind();
        }
     protected void Button3_Click1(object sender, EventArgs e)
        {
            RadGrid1.MasterTableView.TableLayout = GridTableLayout.Auto;
            RadGrid1.AllowFilteringByColumn = false;
            RadGrid1.MasterTableView.AllowFilteringByColumn = false;
            RadGrid1.Rebind();
        }

    Thanks,
    Shinu.
  3. Manishkumar
    Manishkumar avatar
    240 posts
    Member since:
    Feb 2009

    Posted 22 Sep 2011 Link to this post

    Thanks Shinu............
    RadGrid1.MasterTableView.AllowFilteringByColumn = true;
    RadGrid1.Rebind();

    did the trick!!!!

    Thanks a lot.
  4. Srinivas
    Srinivas avatar
    4 posts
    Member since:
    Oct 2013

    Posted 04 Dec 2013 Link to this post

    Hi Shinu,

    In my Application Filtering is not working, Plz Help me..Thanks..

    .aspx:

    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                            ShowStatusBar="true" PageSize="50" AllowSorting="True" Width="100%" GridLines="None"
                            AllowFilteringByColumn="True" OnNeedDataSource="RadGrid1_NeedDataSource" AllowMultiRowSelection="true"
                            EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" Skin="Default"
                            SelectedItemStyle-CssClass="SelectedStyle" OnPreRender="RadGrid1_PreRender">
                            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                            </HeaderContextMenu>
                            <MasterTableView Name="APayments" DataKeyNames="ClientID" Width="100%" AutoGenerateColumns="False">
                                <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                                </ExpandCollapseColumn>
                                <Columns>
                                    <%-- <telerik:GridBoundColumn DataField="ClientID" DataType="System.Int32" HeaderText="<b>ID</b>"
                                        ReadOnly="True" SortExpression="ClientID" UniqueName="ClientID" FilterControlWidth="85%"
                                        CurrentFilterFunction="EqualTo" FilterDelay="4000" ShowFilterIcon="false">
                                    </telerik:GridBoundColumn>--%>
                                    <telerik:GridTemplateColumn DataField="ClientID" HeaderText="<b>ID</b>" AllowFiltering="true"
                                        UniqueName="ClientID" FilterControlWidth="85%" CurrentFilterFunction="EqualTo"
                                        AutoPostBackOnFilter="true" FilterDelay="4000" ShowFilterIcon="false">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkBtnID" runat="server" OnClientClick='<%# String.Format("openWin({0});return false;",Eval("ClientID"))%> '
                                                ForeColor="#0000CC" Text='<%# Eval("ClientID") %>' CommandName="Click" CommandArgument='<%#Eval("ClientID") %>'></asp:LinkButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn DataField="FirstName" HeaderText="<b>First Name</b>" SortExpression="FirstName"
                                        UniqueName="FirstName" AllowFiltering="false">
                                    </telerik:GridBoundColumn>                                
                                  <telerik:GridBoundColumn DataField="LastName" HeaderText="<b>Last Name</b>" SortExpression="LastName"
                                        UniqueName="LastName" AllowFiltering="false" FilterControlWidth="75%">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="MiddleName" HeaderText="<b>Middle Name</b>" SortExpression="MiddleName"
                                        UniqueName="MiddleName" Visible="false" AllowFiltering="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="CompanyName" HeaderText="<b>Company</b>" SortExpression="CompanyName"
                                        UniqueName="CompanyName" AllowFiltering="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="EmailID" HeaderText="<b>EmailID</b>" SortExpression="EmailID"
                                        UniqueName="EmailID" FilterControlWidth="95%" CurrentFilterFunction="EqualTo"
                                        FilterDelay="4000" ShowFilterIcon="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="CreatedDate" HeaderText="<b>Reg Date</b>" SortExpression="CreatedDate"
                                        UniqueName="CreatedDate" AllowFiltering="false" DataFormatString="{0:MM/dd/yyyy}">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn DataField="PreparationStatus" HeaderText="<b>Status</b>"
                                        SortExpression="PreparationStatus" UniqueName="Status" AllowFiltering="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn HeaderText="<b>Status</b>" AllowFiltering="false" UniqueName="StatusUpdate">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkBtnStatus" runat="server" ForeColor="#0000CC" OnClientClick='<%# String.Format("openWinForStatus({0});return false;",Eval("ClientID"))%> '
                                                Text='<%# Eval("PreparationStatus") %>' CommandArgument='<%#Eval("PreparationStatus") %>'></asp:LinkButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <%--<telerik:GridTemplateColumn HeaderText="<b>Status</b>" AllowFiltering="false" UniqueName="StatusUpdate">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkBtnStatus" runat="server" ForeColor="#0000CC" OnClientClick='<%# String.Format("openWinForStatus({0});return false;",Eval("ClientID"))%> '
                                                Text='<%# Eval("PreparationStatus") %>' CommandArgument='<%#Eval("PreparationStatus") %>'></asp:LinkButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>--%>
                                    <telerik:GridTemplateColumn HeaderText="<b>Comments</b>" AllowFiltering="false" UniqueName="Comments">
                                        <ItemTemplate>
                                            <center>
                                                <asp:ImageButton ID="ImgBtnComments" runat="server" ImageAlign="AbsMiddle" ToolTip="Comments"
                                                    OnClientClick='<%# String.Format("openWinForComments({0});return false;",Eval("ClientID"))%> '
                                                    ImageUrl="img1/Comment.png" />
                                            </center>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="AsignedUser">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkBtnUser" runat="server" OnClientClick='<%# String.Format("openWinForAllClients({0});return false;",Eval("ClientID"))%> '
                                                ForeColor="#0000CC" Text="AssignedUser"></asp:LinkButton>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                </Columns>
                                <EditFormSettings>
                                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                    </EditColumn>
                                </EditFormSettings>
                                <PagerStyle AlwaysVisible="True"></PagerStyle>
                            </MasterTableView>
                            <ClientSettings>
                                <ClientEvents OnRowContextMenu="RowContextMenu" OnRowSelected="RowSelected" />
                                <Selecting AllowRowSelect="true" />
                                <Scrolling AllowScroll="false"></Scrolling>
                            </ClientSettings>
                            <FilterMenu EnableImageSprites="False" AutoScrollMinimumHeight="0" AutoScrollMinimumWidth="0">
                            </FilterMenu>
                            <ActiveItemStyle BackColor="White" />
                            <FilterItemStyle HorizontalAlign="Center" />
                            <FilterMenu CssClass="FilterMenuClass2">
                            </FilterMenu>
                        </telerik:RadGrid>



    .cs:

     protected void RadGrid1_PreRender(object sender, EventArgs e)
        {
            try
            {
                RadGrid1.MasterTableView.FilterExpression = "";
                GridColumn column1 = RadGrid1.MasterTableView.GetColumnSafe("EmailID");
                GridColumn column2 = RadGrid1.MasterTableView.GetColumnSafe("ClientID");
                column1.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column1.CurrentFilterValue = "";
                column2.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column2.CurrentFilterValue = "";

                   }
            catch { }
        }





  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Dec 2013 Link to this post

    Hi Srinivas,

    We use Initial Filter if you want to set the initial filter for a RadGrid control so that when the Web page is first loaded, it presents an already-filtered set of data. But in your code its NoFilter which is by default, when the page load there is no filter, hence you don't have to write this code in in PreRender. In case if you need it, below is the modified code.

    C#:
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                RadGrid1.MasterTableView.FilterExpression = "";
                GridColumn column1 = RadGrid1.MasterTableView.GetColumnSafe("EmailID");
                GridColumn column2 = RadGrid1.MasterTableView.GetColumnSafe("ClientID");
                column1.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column1.CurrentFilterValue = "";
                column2.CurrentFilterFunction = GridKnownFunction.NoFilter;
                column2.CurrentFilterValue = "";
                RadGrid1.Rebind();
            }
        }
        catch { }
    }

    Thanks,
    Shinu

  6. Srinivas
    Srinivas avatar
    4 posts
    Member since:
    Oct 2013

    Posted 05 Dec 2013 Link to this post

    I removed, RadGrid1.MasterTableView.FilterExpression=String.Empty  from .cs file.
    Then it is working fine..
    Thanks Shinu..
  7. G
    G avatar
    1 posts
    Member since:
    May 2017

    Posted 08 May 2017 Link to this post

    Please anyone help Filter menu will be displaying under Datepicker
Back to Top