Property Group Descriptor for .NET MAUI DataGrid
The PropertyGroupDescriptor
is used to group the data in a .NET MAUI DataGrid by property from the class that defines your objects.
To use the PropertyGroupDescriptor
, you have to set its PropertyName
(string
) property, which gets or sets the name of the property that is used to retrieve the key by which to group.
You can sort the groups in ascending or descending order by using the
SortOrder
property.
Let's, for example, have the following business object:
Add a sample ViewModel
class with a collection of Person
objects:
Define the DataGrid
:
All that is left is to set is the ViewModel
as BindingContext
of the page:
this.BindingContext = new ViewModel();
Apply the PropertyGroupDescriptor
:
this.dataGrid.GroupDescriptors.Add(new Telerik.Maui.Controls.Compatibility.Common.Data.PropertyGroupDescriptor()
{
PropertyName="Department"
});
Here is how the DataGrid looks when it's grouped: