Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVM what part of pattern responsible for grouping of datagrid

I've been tinkering around with the MVVM pattern and now I'm trying to implement a little application based on it.

This application has a datagrid in which, surprisingly enough, some data is presented. Now I'm trying to add some grouping ability to it. I know how to write this in code (C# and XAML), but I'm wondering in what layer I should put the responsible code.

One part of me tells me it should be in the view, because it's code especially for that specific view. It's not generic and serves one purpos: to group the data.

On the other hand I think I should handle it in the ViewModel using a command. It feels, though, as if I'm contaminating my ViewModel with View specific logic.

Any ligt that can be shed on this?

like image 248
user362397 Avatar asked Jun 11 '10 08:06

user362397


1 Answers

In most of my MVVM apps I try to divide responsibilities like this:

  • The view should just perform a simple translation of viewmodel data to pixels. Usually this results in mostly XAML and very little code behind.
  • The viewmodel should perform view-specific logic like grouping etc. I often even have multiple viewmodels per view. You can have a main viewmodel that exposes a list of sub-viewmodels per group to your view for example to implement grouping.
  • If you have any logic that applies to more than one viewmodel it's probably domain logic and should go into the domain model.

So I think grouping should go in the viewmodel.

like image 79
Mendelt Avatar answered Sep 21 '22 17:09

Mendelt