Calling sort on slickgrid

后端 未结 10 888
我寻月下人不归
我寻月下人不归 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 18:44

    If you want multiple column sorting:

    function grid_sorter(args, grid, dataView) {
        let cols = args.sortCols;
        console.log(cols)
        dataView.sort(function (dataRow1, dataRow2) {
            for (let i = 0, l = cols.length; i < l; i++) {
                let field = cols[i].sortCol.field;
                let sign = cols[i].sortAsc ? 1 : -1;
                let value1 = dataRow1[field], value2 = dataRow2[field];
                let result = (value1 === value2 ? 0 : (value1 > value2 ? 1 : -1)) * sign;
                if (result !== 0) {
                    return result;
                }
            }
            return 0;
        });
        grid.invalidate();
        grid.render();
    }
    
    grid_sorter(default_sorting, grid_2, dataView_2);
    

    cols is an object like this:

    - sortCols {
      - length: 2
      - 0 : {
           "sortAsc: true,
           "sortCol": {
               "field: column_id
            }
          }
      - 1: {..}
    }
    

提交回复
热议问题