This post won't contain any code. I just want to share some basic and well-known things and point to one weird behavior I've found.
So Sorting... or Ordering... or <OrderBy>.
You can add sorting to list view in List Settings -> Edit View in Sort section. There you can add 1 or 2 columns to sort and sorting order. Items will be sorted by the first selected column and then by the second one if they have the same value in the first column.
When user works with the view (browse list items) he can add additional sorting through UI by clicking a header of any column (well, almost any - you can't sort by Multi Lookup columns, User and Group columns with allow multiple selection). In that case selected column will be added as the first item of sorting chain. That means that items will be sort by:
- Column that is added by user through List View UI
- Columns that were added in Sort section of Edit View page.
- Column that is added by user through List View UI
- Title column
Comments