Sorting and Filtering on Foreign key Columns

13 posts, 0 answers
  1. Siva
    Siva avatar
    10 posts
    Member since:
    Sep 2012

    Posted 31 Aug 2009 Link to this post

    Hi,

    I have a grid with some foreign key columns in the datasource. I am converting those to Names by IValueConverter while binding the source. Now I need to do sorting and filtering with those columns. How can I do that. I read about IComparable Interface but where should I implement that?

    Thanks,
    Siva

  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 01 Sep 2009 Link to this post

    Hello Siva,

    You should implement IComparable on the type that is returned by the foreign key. Note that you should also implement equality operators (==) in order to enable distinct filtering on this type.

    All the best,
    Stefan Dobrev
    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Siva
    Siva avatar
    10 posts
    Member since:
    Sep 2012

    Posted 01 Sep 2009 Link to this post

    Hi Stefan,

    Thanks for your reply. I have implemented the IValueConverter interface as mentioned in msdn site(http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx) and binded as static resource to Grid Column.
    I am just converting the ID to corresponding Name(string type) in my converter.
    But when I try to drop the column header in filter area rad grid is throwing errors. Also no sorting working on this converted column. Can you provide code snippet to bind the foreign key converted values to grid also how to implement equality?

    Thanks,
    Siva
  5. Kranthi
    Kranthi avatar
    15 posts
    Member since:
    May 2009

    Posted 03 Sep 2009 Link to this post

    hello telerik,

    any updates on this, as i too have the same requirement. need to sort and group the foreign key columns in radgrid, if you can provide any sample code that would be greatly appreciated as i was working with implementing the IComparable and IEquatable but to no avail..

    thanks in advance
    Kranthi
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 04 Sep 2009 Link to this post

    Hi Kranthi,

    Can you send us small project which demonstrates your case? I'll review your scenario and I'll gladly help you.

    Greetings,
    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.
  7. Siva
    Siva avatar
    10 posts
    Member since:
    Sep 2012

    Posted 04 Sep 2009 Link to this post

    Hi,
    In my case I have implemented the IvalueConveter successfully as follows

        [ValueConversion(typeof(Int32), typeof(string))]
        public class UserNameConverter : IValueConverter
        { 
            string name;
            int id;
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value == null)
                    return string.Empty;

                Int32.TryParse(value.ToString(), out id);
                name = GetUser(id).FirstName ?? string.Empty;
                return name;
            }
        }

    Please tell me where should I implement IComparable and IEquatable interfaces?
    should these also implemented to this converter or on My model layer object (User here).
    If possible send me some sample code for this scenario.

    Thaks,
    Siva.


  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Sep 2009 Link to this post

    Hello Siva,

    Sorting, filtering and grouping is not possible on IValueConverter - converters are for mostly for UI purposes. The grid will perform any data operation against the original data!

    Greetings,
    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.
  9. Siva
    Siva avatar
    10 posts
    Member since:
    Sep 2012

    Posted 10 Sep 2009 Link to this post

    Hi Telerik,

    Thanks for your reply. Is there any other way to show foreign keys in the data as corresponding strings and also to sort on basis of the data displayed?
    Suppose I am displaying User information in my Grid. User has a role and group assigned. so I have GroupID and RoleID in User Object. But I need to show those as Group Name and Role Name also should sort, filter and group by those. How can I do this? For displaying Names instead of ID's I used IvalueConverter. Please tell me how can I achieve all these requirements at once?

    Thanks,
    Siva.
  10. Siva
    Siva avatar
    10 posts
    Member since:
    Sep 2012

    Posted 13 Sep 2009 Link to this post

    Hi,

    This is a simple scenario, almost every one may get across. There should be some way to do this.
    Some one can quickly tell me a solution??

    Thanks,
    Siva.
  11. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 15 Sep 2009 Link to this post

    Hello Siva,

    Similarly to the case with IValueConverter, the grid cannot sort, filter, and group on data that is not available in the data that the grid is boud to. My suggestion is to add a property Group or GroupName to your User class or create a ViewModel if adding those properties to the Users class is not convenient.

    All the best,
    Milan
    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.
  12. mark baer
    mark baer avatar
    142 posts
    Member since:
    Sep 2009

    Posted 17 Feb 2011 Link to this post

    What if you are using Related Fields/Columns.  For instance, my "Project" object has "CategoryId", but I am using the Entity Framework so the Project Object has a "Category" attached and the Category object has Name and Id.

    In the Grid, I can add the Category Column and for the DataField, I have it ="Category.Name" and the data shows correctly.  But when I add that column to the Grouping, the grouping works, but I don't see the Category in the Header?  See html below.

    Help?

    <GroupByExpressions>
         <telerik:GridGroupByExpression>
              <GroupByFields>
                   <telerik:GridGroupByField FieldAlias="Category" FieldName="Category.Name" SortOrder="Ascending">         </telerik:GridGroupByField>
              </GroupByFields>
         </telerik:GridGroupByExpression>
    </GroupByExpressions>

    BTW, I am using the latest download for demoing your controls.  If I can get Grouping/Filtering to work, my employer will probably pay for the upgrade.(We currently have your Silverlight controls).

    Thanks
  13. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 24 Feb 2011 Link to this post

    Hi mark baer,

    If Project object has Category object there is no problem to display or group by a property of Category.

    <telerik:RadGridView Name="playersGrid" 
                                 ItemsSource="{Binding Players}" 
                                 AutoGenerateColumns="False">
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Number}"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Position}"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Country}"/>
            <!-- Child property -->
            <telerik:GridViewDataColumn Header="Child property" DataMemberBinding="{Binding Club.Name}"/>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

    I have also attached a sample application that demonstrated that. 


    Best wishes,
    Milan
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  14. mark baer
    mark baer avatar
    142 posts
    Member since:
    Sep 2009

    Posted 24 Feb 2011 Link to this post

    Great, thanks.

    mark
Back to Top
UI for WPF is Visual Studio 2017 Ready