Filtering on RadGrid not working

17,594

Solution 1

Add DataField for each column or use GridBoundColumns rather than GridTemplateColumns.

Solution 2

Your grid definition looks OK to me - not sure where the issue is. I use the Telerik grid from some time now and what I would do if in your shoes would be to debug my code, see what the MasterTableView.FilterExpression value is inside NeedDataSource and whether the returned records are filtered with that expression and passed to the grid.

Dick

Share:
17,594
Icemanind
Author by

Icemanind

I am a .NET developer. I am proficient in C# and I use ASP.Net Core, Winforms and WPF. I also dabble in React and Xamarin.

Updated on June 28, 2022

Comments

  • Icemanind
    Icemanind almost 2 years

    I created a RadGrid with a couple of fields for filtering and I can't seem to get the filtering to work. I can see it clearly posting back (the ajax spinny circle thing) after typing something in the filter box, however my results are always the same. I am using the following definition in the aspx file:

    <telerik:RadGrid PageSize="4" ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True"
                        AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
                        OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged" Skin="Black" ShowFooter="True"
                        ShowStatusBar="True" AllowFilteringByColumn="True"
                        EnableLinqExpressions="False">
                        <MasterTableView AllowFilteringByColumn="true" Caption="Select a Customer">
                            <Columns>
                                <telerik:GridTemplateColumn CurrentFilterFunction="StartsWith" HeaderText="First Name" AllowFiltering="true" AutoPostBackOnFilter="true">
                                    <ItemTemplate>
                                        <%#GetFirstName(DataBinder.Eval(Container, "DataItem"))%>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Last Name" AllowFiltering="true" AutoPostBackOnFilter="true">
                                    <ItemTemplate>
                                        <%#GetLastName(DataBinder.Eval(Container, "DataItem"))%>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Address">
                                    <ItemTemplate>
                                        <%#GetAddress(DataBinder.Eval(Container, "DataItem"))%>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn HeaderText="Shop">
                                    <ItemTemplate>
                                        <%#GetShopName(DataBinder.Eval(Container, "DataItem"))%>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                            <RowIndicatorColumn>
                                <HeaderStyle Width="20px"></HeaderStyle>
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn>
                                <HeaderStyle Width="20px"></HeaderStyle>
                            </ExpandCollapseColumn>
                        </MasterTableView>
                        <ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="True">
                            <Selecting AllowRowSelect="true" />
                        </ClientSettings>
                        <PagerStyle Mode="NumericPages" />
                    </telerik:RadGrid>
    

    And I got the following in my code behind:

    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        BusinessLayer.Customers Customers = new BusinessLayer.Customers();
    
        Customers.GetBySQLStatement(GetCustomerSQL());
    
        this.RadGrid1.DataSource = Customers;
    }
    

    Any ideas?

    • brentlightsey
      brentlightsey about 14 years
      Any other results of this one? I see a similar issue, but have all GridBoundColumns with the DataField defined. Iny my NeedDataSource event handler, the CurrentFilterFunction and CurrentFilterValues are set correctly for the column(s) filtered.
  • hardba11
    hardba11 about 12 years
    still a relevant answer two years later. Thanks
  • Jack0fshad0ws
    Jack0fshad0ws almost 11 years
    Thanks! voted this answer up.. might not be direct answer to the question but certainly helpful for debugging radgrid filtering issues and helped me.
  • KittMedia
    KittMedia over 8 years
    Please edit your answer and describe your code. Code only answers are not the best option.
  • s.bramblet
    s.bramblet about 6 years
    after searching several posts, the DataField suggestion has worked for me.
  • Mike W
    Mike W over 4 years
    OnNeedDataSource is not firing when I do a filter. Only when the page first loads.