jsgrid
jsgrid copied to clipboard
Sort by multiple columns
Do you plan to add the ability to sort by multiple columns? If so, how soon?
Sorting by multiple columns is really valuable improvement. But it's not in the near future, since there are many more important features to be implemented. Thank you for the request.
+1
@tabalinas I need this multi sort functionality for one of my projects and am looking to get this working and then provide a pull request.
First of all... would you be willing to take a pull request for this item if I did the development for it. (I realize you would need to code review and such)
Second... if you would take a pull request, do you have strong opinions of how it should be implemented? Examples:
-
Should the changes be "non breaking" to other people that have utilized column sorting in code?
-
Would the user just hold the shift key and then click a column heading (via mouse) to add additional columns to the sort?
-
How would we handle multiple sorted column in the sort function.
sort: function(field, order) {
Would field then be a comma delimited list of field names and order be a comma delimited list of field orders: field = 'field1,field2,field3', order = 'asc,asc,desc' Or would it be better to us a Javascript array of objects: [{"field": "field1", "order": "asc"}, {"field": "field2", "order": "asc"}, {"field": "field3", "order": "desc"}, ]
@rburgstaler, thank you for the initiative, I appreciate it. Of course, I would love to take a PR.
Regarding your questions:
- yes, no breaking changes should be introduced for the existing API. Non public stuff can be changed.
- agree, holding shift is the usual way to have multi-column sort
- I do prefer and array of objects
[{ field, order }...]
, sincesort({ field, order })
is already supported.
@tabalinas, Great! I have a couple more comments and questions:
agree, holding shift is the usual way to have multi-column sort
This works great on devices with a shift button and a mouse but not so well on touch devices. I don't have any really good ideas on how to implement this on touch. Maybe after sleeping on it, something will come to mind or you have an idea.
I do prefer and array of objects [{ field, order }...], since sort({ field, order })
Great! My only question is how to handle the filter that is passed to the loadData()
call when grid sorting is enabled. Right now it includes two new properties sortField and sortOrder. What would your preference be for that? Would it make sense to have a property called { "sort": [ {"field": "fld1", "order": "asc"}, ... ] }
and keep sortField and sortOrder in as well to avoid making it a breaking change?
@rburgstaler, on mobile it could be double tap for instance. But proper mobile support is the real challenge, since we need to handle touch events and normalize the behavior. I mean, if we just subscribe on mouse and touch events, both handlers will be triggered.
Regarding sorting: I like your proposal. Could we probably call this param sortParams
? Meaning, we have this field: "sortParams": [ {"field": "fld1", "order": "asc"}, ... ]
in filter
of loadData(filter) { ... }
.
Yeah, mobile does make it challenging.
I mean, if we just subscribe on mouse and touch events, both handlers will be triggered.
I am not 100% sure I know what you mean by this. Somehow you need to distinguish between mouse clicking on a column to reset the sort (on all columns) vs. shift + click to add an additional column to the "multi sort". Maybe we can table the mobile discussion until after it is working at the desktop level?
Could we probably call this param sortParams?
Sounds good to me.
Hi, was this feature ever implemented? I am looking for something like this in my project. Please let me know. Thanks.
Unfortunately no, at first this item had a lot of traction and @tabalinas and I were in the works of developing a plan for how I could accomplish this. Once the group I was working with realized that the use case we were trying to solve could be accomplished with a per column filter, all desire for this item dropped. For the record, I really wanted to get this in there, but it is balance of absolute need, time, and desire.
Any update on this feature?
@rburgstaler Could you eloborate on the column filter? I'm in need of a feature like this too.
+1, I'm getting requests for this as well.
@tabalinas Please share a way to sort the columns which are bound to hierarchical data columns. I usually bind columns at a first or second level of the array. These columns are bound to the Jsgrid but not sortable. Columns which are bound with root fields are sortable.
I have used the custom sorting strategies but it is not working nor the sorter:"string" on the fields.
Please let me know if you know any trick/way to achieve this.