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

change filter string dynamically

5 Answers 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
newbie
Top achievements
Rank 1
newbie asked on 16 Mar 2009, 08:30 PM
I have a gridTemplateColumn that binds to two fileds like below:

<

telerik:GridTemplateColumn HeaderText="Employer/Title" UniqueName="Employer" HeaderStyle-Width="14%"

 

 

 DataField="Employer" CurrentFilterFunction="StartsWith"

 

 

AutoPostBackOnFilter="true">

 

 

<ItemTemplate>

 

 

<b>

 

<%

# Eval("Employer")%></b>

 

 

<br />

 

<%

# Eval("JobTitle")%>&nbsp;

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 


I want the user to be able to search on any of the fields. Like if the user enters 'a' then the filter should look for all the rows which have Employer or JobTitle starting with 'a'.

I cannot specify two values in the datafield.

Is it possible to acieve this functionality?

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Mar 2009, 07:29 AM
Hi,

Check out the following code library which explains on how to implement individual filtering for sub-columns in template column.
Individual filtering and sorting for "sub-columns" in template column

Regards,
Shinu.
0
newbie
Top achievements
Rank 1
answered on 19 Mar 2009, 08:26 PM
I tried that code but it doesn't seem to be working.
I can get the column displayed in the grid, and even the literal control at the bottom shows the right filter expression but for some reason the filter is not getting applied.

<

custom:CustomFilteringColumn DataField1="PolicyNumber" DataField2="PlanType" HeaderText="Policy#/Type"  

 

CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="true"  UniqueName="CustomTemplateColumnPolicyNumber"> 

 

<ItemTemplate>  

 

 

 

<%

# Eval("PolicyNumber")%>  

 

 

<br />  

 

<%

# Eval("PlanType")%>&nbsp;  

 

</ItemTemplate 

 

</custom:CustomFilteringColumn>

This is the aspx.cs code:

 

protected

void RadGridPolicy_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)  

 

 

 

 

 

RadGrid grdPolicy = (RadGrid)sender; 

 

 

if (ViewState["dtPolicy"] != null)

 

if ((Session["filterArgs"] != null))

 

string[] args = ((string)Session["filterArgs"]).Split(new char[] { ',' }); 

 

 

if ((args.Length == 4))

{
grdPolicy.MasterTableView.FilterExpression =

"([" + args[0] + "] LIKE '%" + args[2] + "%' AND [" + args[1] + "] LIKE '%" + args[3] + "%')";  

 

 

 

 

else if ((args.Length == 3))  

{

grdPolicy.MasterTableView.FilterExpression =

"([" + args[0] + "] LIKE '%" + args[2] + "%' OR [" + args[1] + "] LIKE '%" + args[2] + "%')";  

 

 

}

 

 

else  

{

grdPolicy.MasterTableView.FilterExpression =

string.Empty;  

 

 

}

 

 

 

grdPolicy.Controls.Add(

new LiteralControl(grdPolicy.MasterTableView.FilterExpression));  

 

 

 

 

 

DataTable dtPolicy = (DataTable)ViewState["dtPolicy"];

grdPolicy.DataSource = dtPolicy;

}

 

}

 

 

 

 

protected

void RadGridPolicy_ItemCommand(object source, GridCommandEventArgs e)  

 

 

 

 

RadGrid grdPolicy = (RadGrid)source;  

 

 

if ((e.CommandName == RadGrid.FilterCommandName))  

 

Pair filterPair = (Pair)e.CommandArgument;  

 

 

if (((string)(filterPair.First) == "NoFilter"))  

{
Session[

"filterArgs"] = null;  

 

 

grdPolicy.MasterTableView.Rebind();

}

}

}

 

 

 

Am I missing something here?

Issue2 : I have autopostbackonfilter set to true on my other columns. That does not seem to be working here either. Do i need to implement additional functionality to get that to working?

0
Sebastian
Telerik team
answered on 20 Mar 2009, 08:32 AM

Hello newbie,

I am afraid that implementing auto postback on filter for template column with more than one fields in it is not achievable with the built-in RadGrid filtering mechanism. A possible solution for you might be to change the field by which the grid will be filtered dynamically with options inside the command item as illustrated in this online demo of the product:  

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/webmailgrid/defaultcs.aspx 

The alternative would be to use separate dropdowns for filters as illustrates in the code library thread linked by Shinu. If this sample is not operational on your end, please prepare a modified version of it and send it enclosed to a regular support ticket. Thus we will do our best to assist you further in configuring it in par with your preferences.

Also verify that you are using the latest release 2009.1.311 of the RadControls suite or the latest internal build available here.

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
newbie
Top achievements
Rank 1
answered on 23 Mar 2009, 06:26 PM
Sorry if I am creating confusion but I want my cutom filtering column to behave just like the other filtering columns in the grid.
I don't want to put my filter box for that column in the command Item template.

Is there any other way to get the auto postback on filter for the customfilteringcolumn in conjunction with the other columns?

If yes can you show me with the help of an example.

0
Sebastian
Telerik team
answered on 24 Mar 2009, 01:27 PM
Hello newbie,

As explained in my previous post, I am afraid that implementing auto postback on filter for template column with more than one fields in it is not achievable with the built-in RadGrid filtering mechanism.

Therefore, you can either consider the options explained before or have single field displayed in your template column and set the following properties for it:

  • AutoPostBackOnFilter = true
  • CurrentFilterFunction = Contains
  • ShowFilterIcon = false

You can test that for the third column from the following online demo of the product:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filteringtemplatecolumns/defaultcs.aspx

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
newbie
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
newbie
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or