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. Image for the cookie policy date
close icon

Sort/Group SfDataGrid by Column with complex object

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


7 Replies

EM Elavarasan M Syncfusion Team July 4, 2016 01:49 PM UTC

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


BE Bernd July 4, 2016 06:31 PM UTC

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



EM Elavarasan M Syncfusion Team July 5, 2016 07:38 AM UTC

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


BE Bernd July 10, 2016 08:20 PM UTC

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


EM Elavarasan M Syncfusion Team July 12, 2016 03:35 AM UTC

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 



BE Bernd July 27, 2016 09:40 PM UTC

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


SP Sowndaiyan Paulpandi Syncfusion Team July 28, 2016 05:25 AM UTC

Hi Bernd,

Thanks for your update.

Please let us know if you need any other assistance.

Regards,

Sowndaiyan


Loader.
Live Chat Icon For mobile
Up arrow icon