Author Topic: enable multi-column sort via modifier key only  (Read 3563 times)

argo

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 33
    • View Profile
enable multi-column sort via modifier key only
« on: September 16, 2014, 12:24:39 am »
I need to support multi-column sorting but I only want it to work if the user utilizes a modifier key (like shift-click, ctrl-click, or alt-click). When the user does not use a modifier key, I need each column click to sort just the one column and undo any previous column sorting.

In testing, my users found the default behavior very confusing. They expected each column click to immediate sort just that one column unless they specifically used an option to do a multi-column sort (users suggested shift-click and ctrl-click).

Any thoughts on how to accomplish this without modifying the api?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6122
    • View Profile
Re: enable multi-column sort via modifier key only
« Reply #1 on: September 16, 2014, 08:27:16 pm »
That's a good point.

It can be done with combination of headerCellClick event, event modifiers like evt.ctrlClick, evt.shiftClick & evt.altKey.

When ctrl key is used convert dataModel.sortIndx & dataModel.sortDir into arrays and remove arrays otherwise.

you can take the below as a starting point.

http://jsfiddle.net/paramquery/4tyqv61k/7/

argo

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: enable multi-column sort via modifier key only
« Reply #2 on: September 16, 2014, 10:37:32 pm »
Awesome suggestion. I'll look into that. Thanks!

argo

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: enable multi-column sort via modifier key only
« Reply #3 on: September 18, 2014, 02:04:49 am »
I slightly tweaked the code in the fiddle to meet my exact needs, but the event handler worked perfectly. Thank you!

For anyone that wants the same solution, I also added SHIFT-CLICK as a handled behavior, so the line is now:

 if (evt.ctrlKey || evt.shiftKey)