Search code examples
sortingurlparameterspaginationfiltering

How do you handle parameters for sorting, paging and filtering?


This is the usual thing: you have a list of items with several attributes. You can :

  • sort the list according to each of the attributes, in both ascending and descending order
  • filter (search) the items, again on all attributes
  • navigate between different pages of results

All of this gives you differents parameters for a given page:

  • sorting attribute and sorting order
  • pairs of attribute name and values for the filtering
  • page number

How do you handle the propagation of all these paramters between your pages ? Let's say you can edit one item, and when you go back, you'd like to get on the same page you where.

Do you simply put all parameters in the url (and pass them as "return parameters" to the edit page) ? Do you put some in the session (maybe sort and filter parameters) ?


Solution

  • I like to make them part of the URL so that if someone bookmarks the page or emails a link to the page, it will render the page exactly the same way. You can't do that if you depend on session state.