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

programmatically display filter popups?

7 Answers 168 Views
GridView
This is a migrated thread and some comments may be shown as answers.
derrick
Top achievements
Rank 2
derrick asked on 23 Sep 2009, 09:23 PM
Hi,

Is there a method that I can call or override to force the filter popup dialog come up for a certain column?  (I'm building an extended RadGridView where the functions would be controlled by context menus, so I'd like to get rid of the filter icons and have the column filter UI come up based on a context menu click instead).

Thank you,

Derrick M.

7 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 24 Sep 2009, 11:46 AM
Hi Derrick,

You can do this very easily using our powerful extension methods. I've attached small demo application to illustrate you this.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
derrick
Top achievements
Rank 2
answered on 24 Sep 2009, 02:39 PM
Hi,

Thanks!  If I could follow up, there's a couple things that aren't clear to me:

It appears that the ChildrenOfType<FilteringDropDown>() returns a list with one FilteringDropDown for each column--can you confirm that?  (i.e. does the 2nd item in the list always correspond to the 2nd column).

Secondly, if the grid.IsFilteringAllowed is set to false, the returned list contains FilteringDropDown objects with null .FilterDescriptions.  How would I populated a FilterDescription correctly to match what the base functionality would have done?  (I see that it's set the list of distinct values, available actions, etc.--I'd rather not have to duplicate all that logic if there's a way to avoid it).

Thanks,

Derrick


            foreach (var firstFilteringDropDown in this.ChildrenOfType<FilteringDropDown>())
            {
              if (firstFilteringDropDown != null && firstFilteringDropDown.FilterDescription != null)
              {
                if (firstFilteringDropDown.FilterDescription.FieldName == cellDataMember)
                {
                  firstFilteringDropDown.IsDropDownOpen = true;
                  break;
                }
              }
            }

 

0
Vlad
Telerik team
answered on 30 Sep 2009, 06:34 AM
Hi Derrick,

Straight onto your questions:

Indeed ChildrenOfType<> will return list with FilteringDropDown for each column and 2nd item in the list always correspond to the 2nd column.

When IsFilteringAllowed is set to false these drop downs are not populated and you can use directly FilterDescriptors property of the grid to provide filtering.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
derrick
Top achievements
Rank 2
answered on 30 Sep 2009, 01:58 PM
Thank you.

What I ended up doing was leaving the .IsFilteringAllowed enabled and hiding the icons, so that I could use the built-in UI without having to figure out how to build everything.

    private void HideFilteringUI()
    {
      //this hides the filter indicators but leaves IsFilteringAllowed alone
      foreach (GridViewHeaderCell hc in this.ChildrenOfType<GridViewHeaderCell>())
      {
        //setting hc.FilteringUIVisibility = Visibility.Collapsed has the same effect as just setting grid.IsFilteringAllowed=false
        //hc.FilteringUIVisibility = Visibility.Collapsed;
        FilteringDropDown fdd = hc.ChildrenOfType<FilteringDropDown>()[0];
        fdd.Opacity = 0; //hide the icon
        fdd.Width = 1; //resize the header text
      }
    }
0
Reuben Russell
Top achievements
Rank 1
answered on 26 May 2010, 06:54 PM
I attempted the solution said in this thread but it looks like the "firstFilteringDropDown.FilterDescription" is no longer there in the silverlight 4 Q1 release.  There is also the fact that the order that the controls in "ChildrenOfType<FilteringDropDown>())" come back as is not consistant for my project.

In my project I am having to build a dynamic list of columns via code with the columns in a user defined order with a user defined visibility setting with a wizard, so while there are 31 columns that can be shown only 6 are on and those 6 can be in any order on first draw of the control.  This makes the order of the "ChildrenOfType<FilteringDropDown>())" return almost random.

The FilteringDropDown does not have any way (that I have found) to access the column it is attached on.

So is there a solution to that problem?

As a side note, maybe you could add the "IsDropDownOpen" property to the DataViewColumn object so that we can access it directly without having to hunt down the filter control itself.  Call it "IsFilterDropDownOpen" or something.
0
Rossen Hristov
Telerik team
answered on 27 May 2010, 07:58 AM
Hello Reuben Russell,

FilterDescription is obsolete. It is replaced by the FilterDescriptor.

As for your second question -- you should not discover the column from the drop-down, you should do it the other way around, i.e. discover the drop-down from the column. If you need to control the visibility of the drop-down on a per-column basis, then you should find the column of interest first and then find its header cell instead of finding all header cells at once and then trying to decide what column does each one belong to.

As for the property, I am afraid that we will not add one. Imagine that in a future version the filtering is displayed in a completely different manner, i.e. without drop-down. Or if I replace the default header of the column with a custom one that does not include a drop-down (made possible through the column's Header property). What would a property called "IsFilterDropDownOpen" mean and do?

I hope this makes sense. Let us know if you have any other questions.

Kind regards,
Ross
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Reuben Russell
Top achievements
Rank 1
answered on 27 May 2010, 03:16 PM
foreach (GridViewHeaderCell hc in grid.ChildrenOfType<GridViewHeaderCell>())  
{  
  if (hc.Column == column)  
  {  
    currentFdd = hc.ChildrenOfType<FilteringDropDown>()[0];  
    currentFdd.IsDropDownOpen = true;  
    break;  
  }  

Based on the comments I found a way as shown above to get to the correct filter control to show, however with further investigation I found that the FilteringDropDown does not have very much at all that is publicly visible.  As shown in the screen shot attached.

The sugestion to have a "IsFilterDropDownOpen" was to avoid having to hunt down the FilteringDropDown object with 2 extension methods and a loop.  Maybe that property is not the best solution, but feels a little hacky and not intuitive to flip a boolean flag on an object with only 2 publicly visible properties that has to be accessed like this.

EDIT:
Opening the menu in this way will not close any current menus, so if you are using this solution to only open one filter you may have to force any other FilteringDropDown to close.  Code for this is below:

foreach (GridViewHeaderCell hc in grid.ChildrenOfType<GridViewHeaderCell>())  
{  
  var fdd = hc.ChildrenOfType<FilteringDropDown>()[0];  
 
  if (hc.Column == column)  
  {  
    fdd.IsDropDownOpen = true;  
  }  
  else 
  {  
    fdd.IsDropDownOpen = false;  
  }  
Tags
GridView
Asked by
derrick
Top achievements
Rank 2
Answers by
Vlad
Telerik team
derrick
Top achievements
Rank 2
Reuben Russell
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or