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

Filter - Wrong Filter Item seleted after postback

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 11 Sep 2008, 06:49 PM
Hello,

We have trying to use this example to limit the number of filter items. It does filter the items and data correctly. The problem is the filter item highlighted is not the one that was used to do the filter. For Example, I would filter on StartWith and none of the options are selected after the postback. Any help would be great.

protected void RadGrid1_Init(object sender, System.EventArgs e)  
{  
 GridFilterMenu menu = RadGrid1.FilterMenu;  
 int i = 0;  
 while(i < menu.Items.Count)  
 {  
   if(menu.Items[i].Text == "NoFilter" ||  
      menu.Items[i].Text == "Contains" ||  
      menu.Items[i].Text == "EqualTo" ||  
      menu.Items[i].Text == "GreaterThan" ||  
      menu.Items[i].Text == "LessThan")  
   {  
     i++;  
   }  
   else  
   {  
     menu.Items.RemoveAt(i);  
   }  
 }  
}  

3 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 15 Sep 2008, 10:42 AM
Hello Ryan,

Indeed you are correct in your observation. But I'm happy to inform you that our developers has managed to address this issue. Thus the fix will be available in next service pack of this year's Q2 release of RadControls For ASP.NET AJAX. Meanwhile I have updated you telerik points for reporting this.

Please excuse us for any inconvenience this may cause you.

Best wishes,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Iggy
Top achievements
Rank 1
answered on 26 Mar 2009, 02:40 PM
Has this issue been fixed?  I'm running into the same thing in my code using version 2008.3.1314 (.dll file was built 1/27/2009).  The only difference is that after every postback the "NoFilter" option is selected again in the UI but the filter textbox remains with the text. 

Also, I was running into an issue where the FilterExpression is not cleared out between postbacks.  So if you select the Contains option for a column and then after the postback select the DoesNotContain option, the FIlterExpression on the second postback would contain the sql for the Contains AND DoesNotContain filters.  One thing I tried which seemed to work was to clear out the FilterExpression in the Init for the grid (not shown below).  Is this the right thing to do or am I doing something wrong that the filter expression doesn't clear in the first place?  Will this cause issues when I filter on multiple columns?  I would assume so, so is there a way to fix it?

private void _gridGroups_Init(object sender, EventArgs e)  
{  
   GridFilterMenu menu = _gridGroups.FilterMenu;  
   for (int i = menu.Items.Count - 1; i >= 0; i--)  
   {  
      if (menu.Items[i].Text != "NoFilter" &&   
          menu.Items[i].Text != "Contains" &&  
          menu.Items[i].Text != "DoesNotContain" &&  
          menu.Items[i].Text != "StartsWith" &&  
          menu.Items[i].Text != "EndsWith")  
      {  
         menu.Items.RemoveAt(i);  
      }  
   }  

Here's my ItemCommand function to build the SQL for a filter item (based on code from http://www.telerik.com/help/aspnet-ajax/grdcustomoptionforfiltering.html).
private void _gridGroups_ItemCommand(object source, GridCommandEventArgs e)  
{  
    RadGrid grid = (RadGrid) source;  
    if (e.CommandName == RadGrid.FilterCommandName)  
    {  
        if (e.CommandName == RadGrid.FilterCommandName)  
        {  
            Pair filterPair = (Pair)e.CommandArgument;  
            string newFilter = null;  
            string colName = filterPair.Second.ToString();  
            TextBox tbPattern = (e.Item as GridFilteringItem)[colName].Controls[0] as TextBox;  
            e.Canceled = true;  
            string filterTemplate = "(UPPER([Group].[" + filterPair.Second + "]) {0} '{1}" + tbPattern.Text.ToUpper() + "{2}')";  
            switch (filterPair.First.ToString())  
            {  
                case "Contains":  
                    newFilter = string.Format(filterTemplate, "LIKE""%""%");  
                    break;  
                case "DoesNotContain":  
                    newFilter = string.Format(filterTemplate, "NOT LIKE""%""%");  
                    break;  
                case "StartsWith":  
                    newFilter = string.Format(filterTemplate, "LIKE""""%");  
                    break;  
                case "EndsWith":  
                    newFilter = string.Format(filterTemplate, "LIKE""%""");  
                    break;  
            }  
 
            if (newFilter != null)  
            {  
                if (grid.MasterTableView.FilterExpression == "")  
                {  
                    grid.MasterTableView.FilterExpression = newFilter;  
                }  
                else 
                {  
                    grid.MasterTableView.FilterExpression = "((" +  
                      grid.MasterTableView.FilterExpression + ") AND (" + newFilter + "))";  
                }  
                grid.Rebind();  
            }  
        }  
    }  
0
Rosen
Telerik team
answered on 31 Mar 2009, 11:24 AM
Hello Iggy,

The filter menu selection is not preserved due to the fact that you are manually handling the filtering but not setting the filtered column's CurrentFilterFunction and CurrentFilterValue properties.

The second issue is related to the manual handling of the filtering  too. The double addition of expression is caused by the fact that filter expression are only added, however  there should be a check if there is already an expression for the column and if so to be replaced with the new one.

Best wishes,
Rosen
the Telerik team

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