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)?
Which layer should order the columns shown to the user when using MVC?
mvc;order;rendering
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).