Calling sort on slickgrid

后端 未结 10 914
我寻月下人不归
我寻月下人不归 2021-02-04 18:40

In the slickgrid I\'m able to set the sort column and it\'s sort direction using the grid.SetSortColumn(colName,true/false). This only sets the sorting glyph but do

10条回答
  •  灰色年华
    2021-02-04 19:01

    A more clean solution is not to rely on the arguments to onSort but call getSortColumns instead:

      function gridSorter() {
         var scol=grid.getSortColumns();
         if (scol.length===0) return;
         var scolId=scol[0].columnId, asc=scol[0].sortAsc;
         data.sort(function(a, b) {
            var result = a[scolId] > b[scolId] ? 1 : a[scolId] < b[scolId] ? -1 : 0;
            return asc ? result : -result;
         });
         grid.invalidate();
      }
    

    Then do:

      grid.onSort.subscribe(gridSorter);
    

    This will allow to reestablish sorting anytime you want (from example after reloading the data with ajax) simply by calling gridSorter()

提交回复
热议问题