jsgrid icon indicating copy to clipboard operation
jsgrid copied to clipboard

Sort by multiple columns

Open an2323 opened this issue 9 years ago • 13 comments

Do you plan to add the ability to sort by multiple columns? If so, how soon?

an2323 avatar Nov 05 '15 13:11 an2323

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.

tabalinas avatar Nov 06 '15 00:11 tabalinas

+1

mhascak avatar Oct 05 '16 09:10 mhascak

@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 avatar Jan 11 '17 03:01 rburgstaler

@rburgstaler, thank you for the initiative, I appreciate it. Of course, I would love to take a PR.

Regarding your questions:

  1. yes, no breaking changes should be introduced for the existing API. Non public stuff can be changed.
  2. agree, holding shift is the usual way to have multi-column sort
  3. I do prefer and array of objects [{ field, order }...], since sort({ field, order }) is already supported.

tabalinas avatar Jan 13 '17 00:01 tabalinas

@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 avatar Jan 13 '17 02:01 rburgstaler

@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) { ... }.

tabalinas avatar Jan 15 '17 19:01 tabalinas

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.

rburgstaler avatar Jan 17 '17 04:01 rburgstaler

Hi, was this feature ever implemented? I am looking for something like this in my project. Please let me know. Thanks.

aamirbilvani avatar Dec 11 '17 21:12 aamirbilvani

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.

rburgstaler avatar Dec 13 '17 05:12 rburgstaler

Any update on this feature?

Johnwade01 avatar Mar 19 '18 20:03 Johnwade01

@rburgstaler Could you eloborate on the column filter? I'm in need of a feature like this too.

l3d00m avatar Jun 12 '18 11:06 l3d00m

+1, I'm getting requests for this as well.

jknapp25 avatar Sep 10 '18 17:09 jknapp25

@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.

anki7scorp avatar Aug 14 '23 20:08 anki7scorp