<
telerik:GridTemplateColumn HeaderText="Employer/Title" UniqueName="Employer" HeaderStyle-Width="14%"
DataField="Employer" CurrentFilterFunction="StartsWith"
AutoPostBackOnFilter="true">
<ItemTemplate>
<b>
<%
# Eval("Employer")%></b>
<br />
<%
# Eval("JobTitle")%>
</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
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.
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")%>
</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?
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,
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.
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.
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
Sebastian
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.