How would I apply grid column filters that use an OR condition between the user provided filter values?
For example, I have a grid with two columns and the user supplies filter value of column1 = x and column2 = y.
The default query performs ...WHERE column1 = x AND column2 = y
I want the data returned to be based on ...WHERE column1 = x OR column2 = y
Thanks in advance!
For example, I have a grid with two columns and the user supplies filter value of column1 = x and column2 = y.
The default query performs ...WHERE column1 = x AND column2 = y
I want the data returned to be based on ...WHERE column1 = x OR column2 = y
Thanks in advance!
3 Answers, 1 is accepted
0
Hi Jason,
How the grid is bound in your case? Here is an example with LinqDataSource:
Greetings,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
How the grid is bound in your case? Here is an example with LinqDataSource:
| <%@ Page Language="C#" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <script runat="server"> |
| protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e) |
| { |
| LinqDataSource1.Where = |
| RadGrid1.MasterTableView.FilterExpression.Replace("AND", "OR"); |
| } |
| </script> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head runat="server"> |
| <title></title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <div> |
| <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> |
| <telerik:RadGrid ID="RadGrid1" DataSourceID="LinqDataSource1" AllowPaging="true" |
| AllowSorting="true" AllowFilteringByColumn="true" runat="server"> |
| </telerik:RadGrid> |
| <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="DataClassesDataContext" |
| TableName="Customers" onselecting="LinqDataSource1_Selecting"> |
| </asp:LinqDataSource> |
| </div> |
| </form> |
| </body> |
| </html> |
Greetings,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dennis Shtemberg
Top achievements
Rank 1
answered on 10 Sep 2009, 05:57 PM
Do you have an example of doing the same (applying OR conditions in addition to AND) for a grid bound on the client-side, i.e. RadGrid bound to ADO.NET Data Service - http://demos.telerik.com/aspnet-ajax/grid/examples/clientbinding/defaultcs.aspx
0
Hello Dennis,
You may use client-side databinding event to get current query which will be send to the ADO.NET DataService. Similar to the following:
Kind regards,
Rosen
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.
You may use client-side databinding event to get current query which will be send to the ADO.NET DataService. Similar to the following:
| <telerik:RadGrid> |
| <!--...---> |
| <ClientSettings> |
| <ClientEvents OnDataBinding="dataBinding"/> |
| <DataBinding Location="GridAdoNetDataService.svc" SelectCountMethod="GetCount"> |
| <DataService TableName="Products" /> |
| </DataBinding> |
| </ClientSettings> |
| </telerik:RadGrid> |
| <script type="text/javascript"> |
| function dataBinding(sender, args){ |
| args.set_query(args.get_query().replace(/ and /ig," or ")); |
| } |
| </script> |
Kind regards,
Rosen
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.
