Press "Enter" to skip to content

Grouping with Dynamic Data in Xamarin Forms (Part 3)

In the second part of the series about Dynamic Data, we covered how to filter and sort items. In this part, we are going to see how to group items.

How to group 

We are going to extend our restaurant list sample by grouping the items by Category.


Let’s start

1.Create a class to handle the Grouping

When I was researching about grouping, I found this sample, so I decided to create a generic class based on this, to be able to use it for any grouping.

2.Update the List to be a Grouped list

Note: You don’t need to change the source cache, just change the output collection that’s been used in the UI.

3. Apply the grouping to the list

Apply the grouping by adding the Group method to the pipeline specifying the property that will be used as the group key. Also, use Transform to convert the group into the grouped collection generic class type.

4. Bind UI to the output collection and configure ListView for grouping

If you haven’t fallen in love with Dynamic Data yet, stay tuned for the next part of this series with some more Dynamic Data magic tricks.

Check the full source code here.

Happy Dynamic Data!