2

Say you want to render a table with five columns, but you want the order of the columns to be different depending on some specific parameter. This would be very easy to accomplish if the model sets the order. The view can then simply use a loop and create the table accordingly.

However, unless I have misunderstood things, we want to let the view handle how things are rendered (although I guess there may a gray area involved here in terms of what the view "should decide how to render")? It also feels ugly to let the model set formatting / order, but maybe this is another thing I might have misunderstood?

If the view is supposed to deal with the order of the columns, what is a good way to accomplish it (read: having to use a lot of if-statements and other ugly code in the view)?

Kilian Foth
  • 107,706
  • 45
  • 295
  • 310
user1323245
  • 461
  • 2
  • 8
  • 1
    Just to be absolutely clear, it sounds like you're asking about switching the arrangement of columns from displaying Adults, Children, Pets, Vehicles to Vehicles, Children, Pets, Adults; not changing from sorting the rows by ascending Adults to descending Pets, correct? – HABO Jan 14 '14 at 13:42
  • @HABO Yes, that is correct. – user1323245 Jan 14 '14 at 16:13

1 Answers1

2

Split (conceptualy) your View into ViewView and ViewModel. In view model you will have things like order of columns, number of rows on page, current page, whether you are in edit mode. Simply things that you need to store, but does not make sense to store them in model (different view will not use them).

In what form view model is stored depends on view. It can be in session scoped variable on server (in web application), in hidden field (in web application), on mobile device (in mobile application communicating with server, so model itself is on server), just in different class (in standalone desktop/mobile app).

user470365
  • 1,229
  • 6
  • 8