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

Radgrid Filter From Multiple Columns

10 Answers 1014 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 10 Jul 2013, 01:35 PM
Hi All!

I was wondering if it is possible to filter from multiple columns?  For example you have columns: Name, Alias 1, Alias 2, Alias 3.  The three Alias columns are added to the RadGrid but are hidden.  When the User tries to filter on the Name column I would like them to be able to enter in values for Alias 1, Alias 2 or Alias 3 and get a result.  Is this possible?

I am especially interested in adding this functionality to the following demo:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandcombo/defaultcs.aspx

Thanks,
Mark

10 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 15 Jul 2013, 08:15 AM
Hi Mark,

You can use the ItemCommand event handler to prevent the initial filtering and build the filtering expression manually according to your own requirements:
http://www.telerik.com/help/aspnet-ajax/grid-operate-with-filter-expression-manually.html

Here is a similar sample:
http://www.telerik.com/community/code-library/aspnet-ajax/grid/multi-selection-radcombobox-for-filtering-grid.aspx

Hope this helps.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Mark
Top achievements
Rank 1
answered on 15 Jul 2013, 03:01 PM
Eyup,

Thanks for the reply!

I reviewed the links, and I can see how I can intercept the filter command and alter it.  However, I was hoping to be able to apply it specifically to the Google-like Filtering example where the combo box text is changed in the MyCustomFilteringColumnCS file via the SetCurrentFilterValueToControl method.  The filtering is then run in list_ItemsRequested.  I can certainly manipulate the query to give me filtered results that I am looking for, but displaying the available options and automatically populating (auto-suggest/complete?) in the RadComboBox, from the additional columns, are what I am having difficulty with.  Can you please advise?

Thanks,
Mark
0
Mark
Top achievements
Rank 1
answered on 16 Jul 2013, 01:08 PM
Interesting . . . I updated the SQL query for the one column that I want to have filter multiple columns in the Google-like Filtering RadGrid.  When DataBinding at the end of list_ItemsRequested method I am receiving the following error:

"'ColumnName' is neither a DataColumn nor a DataRelation for table."
0
Mark
Top achievements
Rank 1
answered on 17 Jul 2013, 09:06 PM
In the RadGrid Item Command how would you capture the column/field being filtered on as well as the User entry for that filter?
0
Princy
Top achievements
Rank 2
answered on 18 Jul 2013, 06:35 AM
Hi Mark,

Please try the following program to achieve your scenario.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" AllowFilteringByColumn="true"
           ondatabound="RadGrid1_DataBound1" onitemcommand="RadGrid1_ItemCommand">
           <MasterTableView>
               <Columns>
                . . . . . . . . . . . . .
               </Columns>
           </MasterTableView>
</telerik:RadGrid>

C#:
private string gridMessage1 = null, gridMessage2 = null;
protected
void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
   {
       if (e.CommandName == RadGrid.FilterCommandName)
       {
           Pair filterPair = (Pair)e.CommandArgument;
           gridMessage1 = "Current Filter function: '" + filterPair.First + "' for column '" + filterPair.Second + "'";
           TextBox filterBox = (e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0] as TextBox;
           gridMessage2 = "<br> Entered pattern for search: " + filterBox.Text;
       }
   }
   
   private void DisplayMessage(string text)
   {
       RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));
   }
   protected void RadGrid1_DataBound1(object sender, EventArgs e)
   {
       if (!string.IsNullOrEmpty(gridMessage1))
       {
           DisplayMessage(gridMessage1);
           DisplayMessage(gridMessage2);
       }
   }

Thanks,
Princy
0
Mark
Top achievements
Rank 1
answered on 18 Jul 2013, 08:40 PM
Awesome!  Thanks!  That's exactly what I wanted!

Is it possible to apply filtering to another column once the filter value has been intercepted from the filterBox.Text?

Thanks,
Mark
0
Eyup
Telerik team
answered on 23 Jul 2013, 10:25 AM
Hi Mark,

You can use one of the following approaches to initiate a filter command:
http://www.telerik.com/help/aspnet-ajax/grid-fire-command-event-from-code.html
http://www.telerik.com/help/aspnet-ajax/grid-gridtableview-filter.html

Hope this helps.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Princy
Top achievements
Rank 2
answered on 25 Jul 2013, 08:32 AM
Hi Mark,

Can you please elaborate the requirement.

Thanks,
Princy.
0
Princy
Top achievements
Rank 2
answered on 26 Jul 2013, 06:58 AM
Hi Mark,

The requirement is bit confusing for me. Can you please relate the requirement with any of the following scenario?

1. The ‘Name’ column is visible in RadGrid and all other alias columns are hidden for the user. When user types a value in the ‘Name’ filter textbox, you want to show the Name column’s Combobox auto-suggest is filled with matching data in column Name,Alias1,Alias2,Alias3.

2. The Name column is visible in RadGrid and all other alias columns are initially hidden for the user. When user types a value in the ‘Name’ filter textbox, the related value should populate on the other Alias column’s Combobox auto-suggest. That means the alias columns should visible at this time.

Thanks,
Princy.
0
Mark
Top achievements
Rank 1
answered on 26 Jul 2013, 11:40 AM
Princy, 

Please forgive the delay.  It is actually the first scenario you described.   I have resolved the issue by creating a separate query in the custom filtering column class, passing that result back to the main solution class, running another query in item command, using that result (alias) to verify the name, and filtering on name using that result (name). 

Thanks, 
Mark
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Mark
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or