We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Sort/Group SfDataGrid by Column with complex object

Thread ID:

Created:

Updated:

Platform:

Replies:

124842 Jul 3,2016 06:29 PM Jul 28,2016 01:25 AM WPF 7
loading
Tags: SfDataGrid
Bernd
Asked On July 3, 2016 06:29 PM

Hi,

I do struggle sorting my Grid based an a column with a complex object.

I overrode ToString() and implemented IComparable<> for my object and the content of the column shows just fine but when I try to sort nothing happens and when grouping I get one group for each element in my data source.

My CompareTo function is not even called.

Any hints?

Bernd


Elavarasan M [Syncfusion]
Replied On July 4, 2016 09:49 AM

Hi Bernd, 

Thank you for contacting Syncfusion support. 

We have analyzed your query and we are able to sort and group the columns in SfDataGrid with complex object. We suspect you are not setting the UseBindingValue as true to the column which is bound to complex property. Could you please check by setting UseBindingValue as true, please refer the below UG to know more about the UseBindingValue, 


We have also prepared the sample based on this and please find the sample from below.  

 
If the issue is still persists, could you please modify and revert the sample to us based on your application, this will help us to analyze further and provide the better solution to you. 

Regards, 
Elavarasan M

Bernd
Replied On July 4, 2016 02:31 PM

Elavarasa,


thank you for you reply. Unfortunately it does not work for me. I tired you sample and there I can reproduce the error if I add to the XAML

                <syncfusion:GridTextColumn MappingName="Name" UseBindingValue="True" />  <!-- .FirstName ommitted -->

and in the SalesPersonName class I add a

        public override string ToString()
        {
            return firstName + " " + lastName;
        }

What's wrong here?

Regards
Bernd


Elavarasan M [Syncfusion]
Replied On July 5, 2016 03:38 AM

Hi Bernd, 

We have analyzed your query and you can achieve your requirement by implementing IComparable in the SalesPersonName class and you have to compare the FirstName in the CompareTo method like the below code example, 

public class SalesPersonName : NotificationObject , IComparable 
{ 
    private string firstName; 
 
    public string FirstName 
    { 
        get { return firstName; } 
        set { firstName = value; RaisePropertyChanged("FirstName"); } 
    } 
 
    private string lastName; 
 
    public string LastName 
    { 
        get { return lastName; } 
        set { lastName = value; RaisePropertyChanged("LastName"); } 
    } 
 
    public override string ToString() 
    { 
        return firstName + " " + lastName; 
    } 
 
    public int CompareTo(object obj) 
    { 
        SalesPersonName name = (SalesPersonName)obj; 
        return String.Compare(name.FirstName, this.FirstName); 
    } 
} 
 
<syncfusion:GridTextColumn MappingName="Name" UseBindingValue="True" /> 

We have prepared the sample for this and please find the sample from below, 

 
Regards, 
Elavarasan M

Bernd
Replied On July 10, 2016 04:20 PM

Hi,

thnk you for the sample which is working fine.

Unfortunately my program still does not. :-( My CompareTo() function ist called as is the ToString() function but the grouping always results in One group per entry.
If I do implement in my databound object a getter function which builds the string and returns it all works like a charm.

So I have no idea where to look at. Any hints?

Regards
Bernd

Elavarasan M [Syncfusion]
Replied On July 11, 2016 11:35 PM

Hi Bernd, 

Thanks for your update. 
 
We have analyzed your query and could you please modify the sample based on your scenario, this will help us to provide the better solution to you. 

Elavarasan M 


Bernd
Replied On July 27, 2016 05:40 PM

Elavarasan,

right not I am using a workaround by providing a string property directly from the entitiy instead of the complex property.

So thank you for your support.
I will dig deeper here if I have the time but I am almost sure the error is on my side.
Bernd

Sowndaiyan Paulpandi [Syncfusion]
Replied On July 28, 2016 01:25 AM

Hi Bernd,

Thanks for your update.

Please let us know if you need any other assistance.

Regards,

Sowndaiyan


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;