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

RadGrid Sorting with IList<T> with object composition

4 Answers 238 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Troy
Top achievements
Rank 1
Troy asked on 25 Sep 2008, 08:38 PM
Hi,
I'm using an IList<T> of complex objects that are composed of other complex objects as properties.  I can get the RadGrid to sort ok on a regular property of type string.  But when I try to sort on a property that contains another business object, I get this error:

At least one object must implement IComparable.

This is what my code looks like:

<telerik:GridBoundColumn DataField="BatchNumber" HeaderText="Batch Number" SortExpression="BatchNumber" />

<telerik:GridTemplateColumn HeaderText="Client" SortExpression="Client">                   
     <ItemTemplate><%# (((Batch)Container.DataItem).Client).Name %>
     </ItemTemplate>
</telerik:GridTemplateColumn>


The blue property works fine.  I can't figure out what should go in the SortExpression property to show I want the Name property from the Client object to determine my sorting.

Thanks!
Troy

4 Answers, 1 is accepted

Sort by
0
Troy
Top achievements
Rank 1
answered on 25 Sep 2008, 08:48 PM
Nevermind on the first issue I described.  I just found syntax for using a regular GridBoundColumn for composed objects.  The sorting works now, except for columns that have a row with a null object as a property.  I get a null reference error now just on the sorting, but not the initial binding.  Is there a way to get the sorting mechanism to ignore the null object?

Thanks,
Troy
0
Sebastian
Telerik team
answered on 26 Sep 2008, 07:04 AM
Hello Troy,

Basically, sorting with nullable objects should be supported by the sorting mechanism of RadGrid as shown in this online demo of the product:

http://demos.telerik.com/ASPNET/Prometheus/Grid/Examples/Programming/Binding/DefaultCS.aspx

Please compare your code implementation with the one presented in the demo and outline the differences - they can help us track down the reason for the error to eliminate it.

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Troy
Top achievements
Rank 1
answered on 26 Sep 2008, 02:14 PM
The nullable type would be ok, but I'm not using primative types (datetime or int) to use nullable.  I have a custom object with a property as another custom type.  Code is below:

public class Batch
    {
       
        public Batch (string batchNumber, User batchOwner)
        {           
            BatchNumber = batchNumber;           
            BatchOwner = batchOwner;
        }
             
        public virtual string BatchNumber { get; set; }      
        public virtual User BatchOwner { get; set; }
        public virtual User BatchProofer { get; set; }      
    }

As you can see, the BatchProofer property can be null, and that is what is causing the problems on sorting.  I can't make a nullable User type for the property.

Thanks.
Troy
0
Rosen
Telerik team
answered on 26 Sep 2008, 05:13 PM
Hello Troy,

Unfortunately, RadGrid does not support binding to properties of types different then primitive datatypes. Please refer to our help documentation for a list of supported types here.

Best wishes,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Troy
Top achievements
Rank 1
Answers by
Troy
Top achievements
Rank 1
Sebastian
Telerik team
Rosen
Telerik team
Share this question
or