mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

Slickgrid 3 click sorting #1130

Open vipk1234 opened 7 years ago

vipk1234 commented 7 years ago

I'm trying to implement 3 click sorting for slickgrid and i am trying to achieve this by subscribing to onHeaderClick event and keeping track of the number of click so i can implement ascending, descending and reset state. the issue i'm having is when i set sortable flag to true, the default onHeaderClick in slick.grid file gets executed too. Also, i have subscribed to custom onSort event as well and I'm not sure how to all the custom onSort event from the custom onHeaderClick event.

Any suggestions on this would help.

Thank you

6pac commented 7 years ago

suggest using my repo, it's a more up to date version of this one. the best way to mod this would be in the grid code itself slick.grid.js:

function setupColumnSort() {
    ...
      var sortOpts = null;
      var i = 0;
      for (; i < sortColumns.length; i++) {
        if (sortColumns[i].columnId == column.id) {
          sortOpts = sortColumns[i];
          sortOpts.sortAsc = !sortOpts.sortAsc;
          break;
        }
      }

this is where the grid click is handled. changing the logic would be simple. in fact, i'm a big fan of three state clicks so i might add a grid option for that to my repo.

6pac commented 7 years ago

generally with an event, returning the value false stops the default event occurring, as well as events for parent elements.

6pac commented 7 years ago

also, assuming that you are using example-multi-column-sort.html as a starting point

vipk1234 commented 7 years ago

First of all thanks for getting back, I did considered modifying the grid code but this is common library shared by multiple projects where all the other projects want regular sorting accept this one. that's the reason i was trying to edit it by subscribing to the event.