GridView Filter

4 posts, 0 answers
  1. Amit Patel
    Amit Patel avatar
    71 posts
    Member since:
    Sep 2009

    Posted 24 Jun 2010 Link to this post

    GridView Filter

    I would like to display customize name when binding enum property to a column. Right now it would display the Enum Name e.g. “TimeUnit’  as opposed to “Time Unit” with space.  Is there a way to achieve this without too much customization to grid filter?

     Lets say i have Enum and Class like listed below that i would use for binding to GridView, and would expect filter to show "Time Unit" & Work Unit.

    public enum Unit

                    {

                                    [Display("Time Unit")]

                                    TimeUnit,

                                    [Display("Time Unit")]

                                    WorkUnit

                    }

     

    Public class MyClass

    {

                    Public Unit {get; set;}

    }

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 25 Jun 2010 Link to this post

    Hi Amit Patel,

    You could do this by defining a custom attribute and a converter which will read the custom attribute and show the predefined display text.

    I have attached a sample project which demonstrates this approach. 


    All the best,
    Milan
    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. Amit Patel
    Amit Patel avatar
    71 posts
    Member since:
    Sep 2009

    Posted 25 Jun 2010 Link to this post

    Milan,

    Thanks for the quick response! The solution you provided works great when binding to GridViewDataColumn; however, it does not work when binding to GridViewComboBoxColumn using a converter. The Drop down box show a blank value instead of showing the predefined values.  Please let me know if you are able to show the values in drop down box.

    Thanks,
    Amit
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 30 Jun 2010 Link to this post

    Hi Amit Patel,

    Using this with combo columns is a bit more tricky - you should utilize the ItemTemplate property of the combo column:

    <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding UnitType}">
        <telerik:GridViewComboBoxColumn.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Converter={StaticResource enumConverter}}"/>
            </DataTemplate>
        </telerik:GridViewComboBoxColumn.ItemTemplate>
    </telerik:GridViewComboBoxColumn>


    Sincerely yours,
    Milan
    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
Back to Top