GNOME Bugzilla – Bug 112060
Sorting By Multiple columns should be supported
Last modified: 2014-08-03 20:40:26 UTC
A customer has pointed out a feature which Microsoft Outlook has which the GtkTreeView doesnt (it is also available in Excel using their sorting dialog). If in Outlook I want to sort by two columns, I can click to sort by the first column as normal, and then holding down SHIFT, I can click on another column. This will primarily sort by the first column clicked and then subsequently by the second column header clicked. Also, looking over the API for the GtkTreeView, there seems to be no way to do this programatically either, sorting by ONE column alone seems to be the only options (besides writing a sorting algorithm myself and updating column headers manually). I think there needs to be an API to set multiple columns to sort by, for example: gtk_tree_view_set_column_sort_order(mytreeview,3,1,2,-1); The -1 could finish the list of columns. The actual column sort order (i.e. Ascending or Descending) could be obtained from the current API calls (i.e. gtk_tree_view_column_get_sort_order()).
If we implement this, we should make sure to avoid the problem I just noted with the Outlook implementation: It doesn't show visually which sort column is the more relevant one, leaving you confused about wether you're sorting "first by name, then by date" or "first by date, then by name".
This is true! Would you agree that the FIRST, and MOST important column should be made obvious and the others should not? For example, a particular icon above the primary column and another icon to mark all others (secondary, tertiary, etc).
I was thinking of some kind of double arrow, like <<. Unfortunately that doesn't scale to more than two or three columns. By the way, would shift clicking prepend a new sort column or append it. If it appends, then the approach of marking the primary column specially might look a bit awkward: you click on the date column, and the name column changes visually (because it was the sole sort column before, and now is the primary one...). Don't know if that would be a real problem.
I see your point about appending and prepending, and this would acheive quite a flexibility, but I was thinking more along the lines of simplicity to begin with. If the user is unhappy with their sorting, then they can start again. This way ONLY having one method of ordering the sort. Each click (with the shift) would append the sort order (making the first click the primary sort column). But if it is just as easy to implement, then perhaps there could be a Ctrl+Shift+Click to prepend? It has also occured to me, if the user has 4 columns ordered, and they want to remove one of them, should there be a method of doing that or should they have to start again? For example, if columns 3, 1, 5 and 7 are sorted (in that order) and they want to remove column 5 from the sort, should they be able to Shift+Click the column header again to remove it? I would like to see all these if possible (appending, prepending, and removing the selected header to/from the sort).
No, you misunderstood me. I think have all of these is far too complicated. Thinking about the typical use case, additional sort columns should be appended, because you would typically start sorting by the most important criterion, find the list segment which interests you (e.g. all users with name "Frank"), then recognize that you need to "drill down" further (e.g. sort the Franks by age). One thing which would add a lot of power (but which don't remember ever seeing in a treeview) would be the ability to sort only a selected region (e.g. assume you sorted by name, and found all users whose names start with "F", now you want to sort them by age, keeping them together as a block, but mixing the Franks and the Frederics).
The TreeView sortable interface wasn't really designed for this IIRC. It might need some refactoring if we want to get this working. I don't think we are going to have time for 2.4. Putting on future for now.
Why not begin with introducing this feature in the API, and worry about the gui later? After all, not all treeviews even have the column headers visible, nevertheless they use sorting.
(In reply to comment #0) > I think there needs to be an API to set multiple columns to sort by, for > example: > > gtk_tree_view_set_column_sort_order(mytreeview,3,1,2,-1); > > The -1 could finish the list of columns. should this api be added GtkTreeSortable interface or GtkTreeView? TreeModels like GtkListstore or GtkTreeStore will implement this accordingly. I don't see anyone except GtkTreeView might be using this but if some other widget wants this feature it may get it through GtkTreeModels. what is current status of this bug?
closing old bugs