Search code examples
sortingfilteringmvp

Filter/Sort in the view or in the model?


Having a list of data object and something visual to represent each, where would you code the sorting/filtering logic? Why?

Edit : All the answers so far are good, but I forgot to add another constraint. What if I don't want to reconstruct the view each time?


Solution

  • The answer lies in the data. The model delivers the data. If all the data is in the view, the filtering and sorting can be contained within the view. If the data is chunked, the model must deliver the data and contain some of filtering/sorting (the view may still contain filtering/sorting as well).

    The controller should not contain these functions, since it is a routing mechanism and should not have any idea of how to interpret the data.