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

[Solved] How to enable sorting / filter on custom GridViewColumn

3 Answers 265 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jeffery
Top achievements
Rank 1
Jeffery asked on 10 Mar 2010, 10:52 PM

I am trying to create cutom gridview column, like this:

    public class MyDataColumn : GridViewDataColumn  
    {  
        public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)  
        {  
            var presenter = new TextBlock();  
 
            var opp = dataItem as TestData;  
            if (opp == nullreturn presenter;  
 
            // Do something here ...  
 
            return presenter;  
        }  
    } 

I am able to add the column to grid before set ItemSource:

            Grid1.Columns.Add(new MyDataColumn  
                                  {  
                                      Header = "My Data Column",  
                                      IsReadOnly = true,  
                                      IsSortable = true,  
                                      IsFilterable = true 
                                  }); 

 

 

The column looks fine.  However, sorting and filter are not there for the column.  What should I do to enable them?  Also, what should I do to support export for the custom column?

Thanks in advance.

P.S. I have create a sample project for this.  Unfortunately, I could not attach a zip file with this post.  If you need it to understand what I am trying to achive here, I can eamil it to you.

 

 

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 11 Mar 2010, 08:10 AM
Hi,

You need to set DataMemberBinding if you want sorting, filtering, grouping, etc.

Best wishes,
Vlad
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
Jeffery
Top achievements
Rank 1
answered on 11 Mar 2010, 03:36 PM
Thanks for the quick replay.

However, I could not really do / do not really know how to do that.  The actual data shown in the cell is not in the ItemSource for the GridView.  I use a converter to set the content.  The code I have is quite like what mentioned in this post: http://www.telerik.com/community/forums/wpf/gridview/calculated-columns.aspx.

Could you please give me some idea?

Thanks.
0
Vlad
Telerik team
answered on 11 Mar 2010, 03:54 PM
Hi,

If you want dynamic objects binding you can check my DataTable for more info.

Sincerely yours,
Vlad
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.
Tags
GridView
Asked by
Jeffery
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Jeffery
Top achievements
Rank 1
Share this question
or