Custom filter rows

11 posts, 1 answers
  1. Laurian Angelescu
    Laurian Angelescu avatar
    10 posts
    Member since:
    Apr 2010

    Posted 20 May 2010 Link to this post

    Hello Telerik,

    I am attempting to implement a custom header row for the radgridview. I have an issue, however, in that only the first column of the six columns in the grid contains a filter control underneath. The others do not show any trace of customization. Tracing through the source code I can see that in the method InitializeFilters found in the sample GridViewFilterRow.cs file, the call that retrieves the cells only gets back one value (the first column).

      private void InitializeFilters(GridViewHeaderRow row)  
            {  
                row.Height = 50;  
     
                // Get all header cells.  
                IEnumerable<GridViewHeaderCell> cells = row.Cells.OfType<GridViewHeaderCell>();  
     
                FieldFilterDescriptor ffd = null;  
     
                foreach ( GridViewHeaderCell cell in cells )  
                {  
                    // Loop only on data columns. 

    The second column of the grid is identical to the first, it's bound to a string data type, to the same data member, but another subproperty. Both columns are visibly filled with data. Do you have any hints?

    I attempted to put together a test project illustrating the issue, but I hit another roadblock in that radGridView_Loader

     void radGridView_Loaded(object sender, RoutedEventArgs e)  
            {  
                GridViewHeaderRow headerRow = radGridView.ChildrenOfType<GridViewHeaderRow>().FirstOrDefault();  
                if (headerRow != null)  
                {  
                    InitializeFilters(headerRow);  
                }  
            } 
    will get a headerRow object that is null. I did verify the IsEnabled property is set to true.

    This miniature test project can be downloaded from http://drop.io/telerik/asset/testradcontrolssolution-7z .

    Thanks.

  2. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 May 2010 Link to this post

    Hi Laurian Angelescu,

    It seems in your case the Loaded event of the gridview fires before the visual tree is fully initialized and the InitializeFilters was not fired for each cell. What you need to do is subscribe to the LayoutLoaded event instead.
    We will improve the online demo for the next official release scheduled for the beginning of June.

    Here is how it should look like:

    private void Attach()
    {
        if (radGridView != null)
        {
          this.radGridView.LayoutUpdated += new EventHandler(radGridView_LayoutUpdated);
        }
    }
     
    void radGridView_LayoutUpdated(object sender, EventArgs e)
    {
        GridViewHeaderRow headerRow = radGridView.ChildrenOfType<GridViewHeaderRow>().FirstOrDefault();
        if (headerRow != null)
        {
             InitializeFilters(headerRow);
        this.radGridView.LayoutUpdated -= radGridView_LayoutUpdated;
        }
    }


    Hope this helps.

    Sincerely yours,
    Veskoni
    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.
  3. DevCraft banner
  4. Laurian Angelescu
    Laurian Angelescu avatar
    10 posts
    Member since:
    Apr 2010

    Posted 21 May 2010 Link to this post

    Thanks for the help Veskoni, it sent me on the right direction.

    What happens is that even with the new behavior, since we're calling InitializeFilters() on the first firing of the LayoutUpdated event and then we remove the event handler, the visual tree still does not contain all the cells in the header row.

    I have verified however that if I did not unwire the LayoutUpdated event handler right away, after the second or third call, all the cells will be retrieved.

    What I did instead, and worked in my case, was to call UpdateLayout() before initializing the filters. Like so:

    void radGridView_Loaded(object sender, RoutedEventArgs e)     
            {     
                GridViewHeaderRow headerRow = radGridView.ChildrenOfType<GridViewHeaderRow>().FirstOrDefault();
                headerRow.UpdateLayout();     
                if (headerRow != null)     
                {     
                    InitializeFilters(headerRow);     
                }     
            }    
     

    This gives me exactly the results I want. So to clarify, I am still using the Loaded event.

  5. Shumskikh Alexander
    Shumskikh Alexander avatar
    3 posts
    Member since:
    Mar 2010

    Posted 31 May 2010 Link to this post

    Hi,

    i have the same problem described it the first post, but none of suggested solutions work. Filter appears only on the first column... Thanks for any help and suggestions!

    PS: AutoGenerateColumns="False"
  6. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 31 May 2010 Link to this post

    Hello Shumskikh Alexander,

     You can handle the RowLoaded event. Check if the new row (it's a property on the event args) is of type GridViewHeaderRow. If so, call InitializeFilters. You don't even need to remove your event handler from the event afterwards.

    Regards,
    Yavor Georgiev
    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.
  7. Shumskikh Alexander
    Shumskikh Alexander avatar
    3 posts
    Member since:
    Mar 2010

    Posted 01 Jun 2010 Link to this post

    Thanks, Yavor! But your solution gives the same result...

    My modification:
            private void Attach() 
            { 
                if (_radGridView != null
                { 
                    this._radGridView.RowLoaded += _radGridView_RowLoaded; 
                } 
            } 
     
            void _radGridView_RowLoaded(object sender, RowLoadedEventArgs e) 
            { 
                var header = e.Row as GridViewHeaderRow; 
                if (header != null
                { 
                    InitializeFilters(header); 
                } 
            } 

    But filter still appears only on the first column (There is only one cell object, when i set breakpoint and inspect "header" variable).
    My grid binded to custom CollectionView object (its class implements ICollectionView, IPagedCollectionView, INotifyPropertyChanged interfaces) which uses WCF services. May the root of the problem be somewhere there?


  8. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 01 Jun 2010 Link to this post

    Hello Shumskikh Alexander,

     We will provide an updated and more reliable version of the CustomFilterRows example in our SP2 release, which is almost out of the door.

    Greetings,
    Yavor Georgiev
    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.
  9. Fabrice Marguerie
    Fabrice Marguerie avatar
    9 posts
    Member since:
    May 2010

    Posted 11 Jun 2010 Link to this post

    Would you have that update sample readily available, please?
    The documentation for Q2 Beta has not been updated yet.

    Please ensure that the update code sample works fine with EnableColumnVirtualization="True".
    The current sample code doesn't work fine because with column virtualization not all column headers are available all the time.

    Could you please improve the code sample so that we can use this kind of filter row without having to set EnableColumnVirtualization to False?
  10. Fabrice Marguerie
    Fabrice Marguerie avatar
    9 posts
    Member since:
    May 2010

    Posted 12 Jun 2010 Link to this post

    Although the documentation hasn't yet been updated, the code sample in Demos\Examples\GridView\CustomFilterRow has.
    After a few tweaks, it works fine now.
    Thanks!

    One last thing: what would it take to have the filter displayed correctly with frozen columns?
  11. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 15 Jun 2010 Link to this post

    Hello Fabrice Marguerie,

     I'm sorry, but after some research I have determined that it is not viable for the CustomFilterRow to tap into the column freezing mechanism of the GridView. To do that, it'd need to be a part of the GridView, not a separate UserControl and currently there are no plans to move it into the main controls suite.

    Regards,
    Yavor Georgiev
    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.
  12. Fabrice Marguerie
    Fabrice Marguerie avatar
    9 posts
    Member since:
    May 2010

    Posted 15 Jun 2010 Link to this post

    Thanks for your reply.
    I managed to make it work fine at least with one frozen column. This is my personal use case.

    Fabrice
Back to Top
DevCraft banner