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

[Solved] Custom Grouping using DelegateGroupDescriptor

4 Answers 138 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rajesh
Top achievements
Rank 1
Rajesh asked on 19 Jun 2014, 10:48 AM
Hi,

I want to group the data in a Grid by a column in a specific sort order. I have specified the order in the SQL Query and the data is returned in the correct way.

But when grouping it to a RAD Grid it groups it alphabetically.for that column specified in the PropertyName

<telerikGrid:RadDataGrid.GroupDescriptors>
     <telerikGrid:PropertyGroupDescriptor PropertyName="Room" />
</telerikGrid:RadDataGrid.GroupDescriptors>


What I want is to group by the column specified in the SQL query.

I went through the DelegateGroupDescriptor and wrote the following Code

public class CustomIKeyLookup : IKeyLookup
    {
        public object GetKey(object instance)
        {
            return (instance as QuestionDetails).CategoryID;
        }
    }

and in the XAML file

<telerikGrid:DelegateGroupDescriptor>
    <telerikGrid:DelegateGroupDescriptor.KeyLookup>
    <local:CustomIKeyLookup />
    </telerikGrid:DelegateGroupDescriptor.KeyLookup>
</telerikGrid:DelegateGroupDescriptor>

But I am getting an error which says that CustomIKeyLookup is not a member of the class file where the XAML code resides.

What exactly is wrong in this case.

And I went through this thread with a similar doubt (http://www.telerik.com/forums/custom-sorting-of-grouping). But it never used the DelegateGroupDescriptor. Why is this so.

Thanks,

Rajesh.



4 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 23 Jun 2014, 04:40 PM
Hi Rajesh,

I have attached a sample project that demonstrates how you can group the items using a PropertyGroupDescriptor that groups the items by CategoryID and using the RadDataGrid.GroupHeaderTemplate property you can edit the group header content.

I hope this helps. Please, let us know if you have any other questions.

Regards,
Rosy Topchiyska
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajesh
Top achievements
Rank 1
answered on 30 Jun 2014, 11:43 AM
Hi,

I went through your sample and observed the change in the code to make it work.

However in my case, it is not working as expected. I am sending you the screen shots of my query, and outcome in the application.

Explanation:

We have rooms that are identified by CategoryID. Since we are grouping by CategoryID in the SQL Statement the order of the rooms should be 

CategoryID DName

101272 Living Room
101285 Kitchen
101302 Bathroom
101318 Bedroom or Any Other Room Used for Sleeping (regardless of type of room)
101320 Dining Room or Dining Area
101321 Second Living Room, Family Room, Den, Playroom, TV Room
101322 Entrance Halls, Corridors, Halls, Staircases
101323 Additional Bathroom (also check presence of sink trap and clogged toilet)
101324 Other
101325 All Secondary Rooms (Rooms not used for living)
101326 Building Exterior
101327 Heating and Plumbing
101328 General Health and Safety

But the rooms are sorted in alphabetical order. I have modified the code as per the sample and when attempting to use the CategoryID in the group header definition I am getting the output as seen in CustomSort_4.png.

Is there any criteria for the data to be so that the custom sorting can be implemented as per our requirements.

Thanks,

Rajesh.

 
0
Accepted
Tsvyatko
Telerik team
answered on 03 Jul 2014, 07:26 AM
Hello Rajesh,

Based on the images sent, I can assume that you have defined property descriptor:
<telerikGrid:PropertyGroupDescriptor PropertyName="CategoryID"/>

However, it seems that the GroupHeader template is not redifined as shown in the example:

<local:RoomConverter x:Key="GroupConverter"/>

<telerikGrid:RadDataGrid.GroupHeaderTemplate>
    <DataTemplate>
        <TextBlock Text="{Binding Converter={StaticResource GroupConverter}}"/>
    </DataTemplate>
</telerikGrid:RadDataGrid.GroupHeaderTemplate>

public class RoomConverter : IValueConverter
   {
       public object Convert(object value, Type targetType, object parameter, string language)
       {
           var room = ((value as GroupHeaderContext).Group.ChildItems.FirstOrDefault() as QuestionDetails).RoomName;
           return room;
       }
 
       public object ConvertBack(object value, Type targetType, object parameter, string language)
       {
           // TODO: Implement this method
           throw new NotImplementedException();
       }
   }


Could you double check that these modifications are applied. If this does not help, you can open support thread and attach striped down version of the project demonstrating the issue you are facing.


Regards,
Tsvyatko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajesh
Top achievements
Rank 1
answered on 18 Aug 2014, 05:46 AM
Hi,

Thanks for your reply and I had overlooked a fragment of the code. Now everything works as expected.

Thanks a lot.
Tags
Grid for XAML
Asked by
Rajesh
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Rajesh
Top achievements
Rank 1
Tsvyatko
Telerik team
Share this question
or