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

RadGrid CurrentFilterFunction="StartsWith" not working

17 Answers 448 Views
Grid
This is a migrated thread and some comments may be shown as answers.
daniel liu
Top achievements
Rank 1
daniel liu asked on 03 Dec 2009, 07:46 PM

Hi,

I have problem for RadGrid filtering, even I set CurrentFilterFunction="StartsWith", but filtering always filter as "contains", here is my code for RadGrid, is anything wrong?

thanks

 

<telerik:RadGrid AutoGenerateColumns="false" ID="RadGrid1"

 

 

Width="800px" AllowFilteringByColumn="True" AllowSorting="True"

 

 

ShowFooter="True" AllowPaging="True" runat="server"

 

 

GridLines="None" EnableLinqExpressions="false">

 

 

<GroupingSettings CaseSensitive="false" />

 

 

<MasterTableView AutoGenerateColumns="false" EditMode="InPlace" AllowFilteringByColumn="True"

 

 

ShowFooter="True" TableLayout="Fixed">

 

 

<Columns>

 

 

<telerik:GridBoundColumn FilterControlWidth="60px" DataField="DONOR" HeaderText="DONOR" SortExpression="DONOR"

 

 

UniqueName="DONOR" AutoPostBackOnFilter="true" CurrentFilterFunction="StartsWith" ShowFilterIcon="false">

 

 

</telerik:GridBoundColumn>

........

 

17 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Dec 2009, 10:08 AM
Hi,

Are you facing an issue similar to the one mentioned in the forum link.If so the Telerik team has offered a solution

CurrentFilterFunction defaults back to Contains? 

 

If this doesnot help could you mention the steps performed to achieve filtering

Thanks,
Princy

0
daniel liu
Top achievements
Rank 1
answered on 04 Dec 2009, 06:18 PM
Thanks for prompt reply. The problem comes from the enter key press inside filter textboxes.

1.
Would you please provide any sample client side script to disable postback from enter key press inside filter textboxes?
2.
or Would you please provide any sample client side script to check the value of the filter textbox, and cancel out the bubbling of the enter key press if there is no value?

Thanks

daniel

0
daniel liu
Top achievements
Rank 1
answered on 04 Dec 2009, 07:19 PM
I tested many times, if I input more than one filter boxes, it become "Cantains" filtering, even I did not press enter key.

Is it anyway to enforce CurrentFilterFunction="StartsWith" from server side C# code?

thanks

daniel
0
daniel liu
Top achievements
Rank 1
answered on 04 Dec 2009, 08:30 PM

After I tested filter more than 10 times, following javascript scripting error thrown:

j.href=j.href.replace(

"&ie7CacheFix","")

seems filter function is not matual yet.

thanks

daniel

 

0
daniel liu
Top achievements
Rank 1
answered on 04 Dec 2009, 11:22 PM
"If this doesnot help could you mention the steps performed to achieve filtering".

We could not use DataSourceID as your basic filtering sample, What I did is to bind RadGrid from c# code :

 

protected void Page_Load(object sender, EventArgs e)

 

{
    loadGrid();
}

The filter function is not working this way. 

If you try bind RadGrid from c# codebehind, you would see the problems.

thanks

daniel

0
Princy
Top achievements
Rank 2
answered on 07 Dec 2009, 12:06 PM
Hi Daniel,

Simple data-binding cannot be used to perform complex operations such as filtering. Thus, try binding the Grid in the NeedDataSource event of the grid and see if it makes any difference. You can refer the following online demo to find out more on AdvanceDataBinding techniques.
Advanced data-binding

Thanks
Princy.
0
daniel liu
Top achievements
Rank 1
answered on 07 Dec 2009, 06:19 PM

 

I used NeedDataSource as following, but still the same problem, CurrentFilterFunction="StartsWith" only works for the first time filtering, if I try to filter any textbox after first time filtering, it becomes CurrentFilterFunction="Contains".

Would you please test it on your side and give us the correct answer to fix this bug???

thanks for your quick response!

daniel


<
telerik:RadGrid AutoGenerateColumns="false" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource"

 

 

Width="800px" AllowFilteringByColumn="True" AllowSorting="True"

 

 

ShowFooter="True" AllowPaging="True" runat="server"

 

 

GridLines="None" EnableLinqExpressions="false">

 

 

<GroupingSettings CaseSensitive="false" />

 

 

<MasterTableView AutoGenerateColumns="false" EditMode="InPlace" AllowFilteringByColumn="True"

 

 

ShowFooter="True" TableLayout="Fixed">

 

 

<Columns>

 

 

<telerik:GridBoundColumn FilterControlWidth="60px" DataField="DONOR" HeaderText="DONOR" SortExpression="DONOR"

 

 

UniqueName="DONOR" AutoPostBackOnFilter="true" CurrentFilterFunction="StartsWith" ShowFilterIcon="false">

 

 

</telerik:GridBoundColumn>
......


 

 

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

 

{

 

IQueryable<COG_ACTION_STAGE_VW> query = GetDataForGrid();

 

 

this.RadGrid1.DataSource = query;

 

}

 


0
daniel liu
Top achievements
Rank 1
answered on 07 Dec 2009, 06:38 PM
I double checked your demo site: http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/filtering/defaultcs.aspx

It only has "Contains" filtering with ShowFilterIcon="false" for Textbox filter,

did you ever tested 

 

CurrentFilterFunction="StartsWith" ShowFilterIcon="false"???

thanks

daniel

 

0
Pavel
Telerik team
answered on 10 Dec 2009, 03:25 PM
Hello daniel,

In order to make this work after the filter of the Grid is cleared you should set the CurrentFilterFunction for the respective column on the PreRender event handler of the page similar to the following:
protected void Page_PreRender(object sender, EventArgs e)
{
    RadGrid1.Columns[0].CurrentFilterFunction = Telerik.Web.UI.GridKnownFunction.StartsWith;
}


Sincerely yours,
Pavel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
daniel liu
Top achievements
Rank 1
answered on 10 Dec 2009, 07:20 PM
yes, it works this way.

thanks
0
Ismail Ahmed Syed
Top achievements
Rank 2
answered on 12 Jan 2010, 04:26 AM
Hi, I dont want to show all the options of filtering on click of filter image and set it permeanently to "startswith", any help would be really appreciated.
0
Princy
Top achievements
Rank 2
answered on 12 Jan 2010, 06:48 AM
Hi Ismail,

You can go through the following help document which explains on how to reduce the filter options in the filter menu:
Reducing the filter menu options

-Princy.
0
Ismail Ahmed Syed
Top achievements
Rank 2
answered on 25 Jan 2010, 11:44 PM
Thanks for the info, i incorporated that
0
Aswin S
Top achievements
Rank 1
answered on 09 Feb 2010, 08:54 AM
Thanks Pavel. That helped.
But why the initialized currentfilterfunction property loses its value

is this a bug ?
0
Pavel
Telerik team
answered on 09 Feb 2010, 03:20 PM
Hi Aswin,

The observed behavior is the expected one when the CurrentFilterFunction property is set in the markup. If you want to persist it you need to use the approach suggested previously.

Sincerely yours,
Pavel
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Matthew Hart
Top achievements
Rank 1
answered on 13 Mar 2014, 07:00 PM
Yes. In my opinion it certainly is a bug. It is ridiculous to keep writing more and more code to get the filter to filter as any normal user would expect. When a user enters "E" they want to see the values that start with e. Any other result is completly unexpected and usually worthless. It may be nice to have other filter options, but any typical user would expect the default to be "begins with." I have seen no viable solutions on this site despite the question being asked over and over.
0
Viktor Tachev
Telerik team
answered on 18 Mar 2014, 11:56 AM
Hello Matthew,

In order to set the default filter function for a column you could use itsCurrentFilterFunction property. I tested the following setup and it seems to work as expected on my end. The Description column was filtered using the StartsWith function. I used the 2014.1.225 version of the controls for testing.

<telerik:RadGrid runat="server" ID="RadGrid1" Skin="Default"
    OnNeedDataSource="RadGrid1_NeedDataSource"
    AutoGenerateColumns="false"
    AllowPaging="true" PageSize="10"
    AllowFilteringByColumn="true">
 
    <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID">
        <Columns>
            <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" AutoPostBackOnFilter="true" ShowFilterIcon="false">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Description" HeaderText="Description" UniqueName="Description" AutoPostBackOnFilter="true"  CurrentFilterFunction="StartsWith" >
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

For convenience I am also attaching the sample project I tested with. Give it a try and let me know if it is working for you.

Regards,
Viktor Tachev
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
Grid
Asked by
daniel liu
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
daniel liu
Top achievements
Rank 1
Pavel
Telerik team
Ismail Ahmed Syed
Top achievements
Rank 2
Aswin S
Top achievements
Rank 1
Matthew Hart
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or