Search code examples
javascriptslickgrid

Fixed one row at the bottom when sorting slickgrid


I have implemented simple sort function.

Thanks to this article

Now I would like to keep one row fixed and sort other rows. (ex, total row should be fixed at the bottom.)

These are my code,

When I click sort column dataView.sort looks like called for each rows.

setSort(){ // I implemented function as class function
  var self = this;
  this.grid.onSort.subscribe(function (e, args) {

    var cols = args.sortCols;
    self.dataView.sort(function (dataRow1, dataRow2) {

      for (var i = 0, l = cols.length; i < l; i++) {
        var field = cols[i].sortCol.field;
        var sign = cols[i].sortAsc ? 1 : -1;
        var value1 = dataRow1[field], value2 = dataRow2[field];
        var result = (value1 == value2 ? 0 : (value1 > value2 ? 1 : -1)) * sign;

        if (result != 0) {
          return result;
        }
      }
      return 0;
    });
    self.grid.invalidate();
    self.grid.render();
  });
}

Solution

  • Have you checked out the standard examples?

    eg. this one