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

Custom filter rows

10 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Laurian Angelescu
Top achievements
Rank 1
Laurian Angelescu asked on 20 May 2010, 11:02 PM
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.

10 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 21 May 2010, 02:16 PM
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.
0
Laurian Angelescu
Top achievements
Rank 1
answered on 21 May 2010, 03:20 PM
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.

0
Shumskikh Alexander
Top achievements
Rank 1
answered on 31 May 2010, 07:55 AM
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"
0
Yavor Georgiev
Telerik team
answered on 31 May 2010, 05:33 PM
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.
0
Shumskikh Alexander
Top achievements
Rank 1
answered on 01 Jun 2010, 10:34 AM
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?


0
Yavor Georgiev
Telerik team
answered on 01 Jun 2010, 11:04 AM
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.
0
Fabrice Marguerie
Top achievements
Rank 1
answered on 12 Jun 2010, 12:09 AM
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?
0
Fabrice Marguerie
Top achievements
Rank 1
answered on 12 Jun 2010, 07:07 PM
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?
0
Yavor Georgiev
Telerik team
answered on 15 Jun 2010, 01:05 PM
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.
0
Fabrice Marguerie
Top achievements
Rank 1
answered on 15 Jun 2010, 01:17 PM
Thanks for your reply.
I managed to make it work fine at least with one frozen column. This is my personal use case.

Fabrice
Tags
GridView
Asked by
Laurian Angelescu
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Laurian Angelescu
Top achievements
Rank 1
Shumskikh Alexander
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Fabrice Marguerie
Top achievements
Rank 1
Share this question
or