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

[Solved] Cleanest way to get filter information?

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 29 Mar 2013, 02:08 PM
I'm trying to find the cleanest format in which I can get the current filters entered on a postback.  The only place I'm able to find it is in the MasterTableView.FilterExpression string.  An example of how that looks is:

(it["Continent"].ToString().Contains("Af")) AND (it["Country"].ToString().Contains("So"))

I'm just wondering if there's a way to get this information in a nicer format.  

Eventually I need to turn this information into sql, and I'll need to create a helper method to make that translation (unless someone knows of one that already exists).

Thanks,
Alex

Edit: to further complicate matters it appears that sometimes the filter expression can be in a different format, for example:
(Convert.ToString(it[\"CategoryName\"]) >= \"Bev\")

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Apr 2013, 05:08 AM
Hi,

You can check for the filter function in grid in the ItemCommand event. Check the following help documentation for more,
Operating with the FilterExpression of Telerik RadGrid Manually

Thanks,
Shinu
0
Alex
Top achievements
Rank 1
answered on 01 Apr 2013, 12:41 PM
Thanks for your reply, but that only gets the newest filter, and only if this postback is that filter command.  What I want is a list of all the filters currently being used on any postback.
0
Shinu
Top achievements
Rank 2
answered on 02 Apr 2013, 05:34 AM
Hi,

C#:
public static string filter =string.Empty;
void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.FilterCommandName)
  {
   Pair filterPair = (Pair)e.CommandArgument;
   filter = filterPair.Second.ToString();
  }
}
protected void Button1_Click(object sender, EventArgs e)
{
 foreach (GridColumn item in RadGrid1.MasterTableView.Columns)
 {
    string filterFunction = RadGrid1.MasterTableView.GetColumn(filter).CurrentFilterFunction.ToString();
    string filterValue = RadGrid1.MasterTableView.GetColumn(filter).CurrentFilterValue;
 }
}

Thanks,
Shinu
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Alex
Top achievements
Rank 1
Share this question
or