views:

130

answers:

1

I'm using Slickgrid but I'd prefer not to use slick.model.js. How can I write grid.onSort to sort the lines of my data set?

My code uses the standard template:

 $(function() {
        var data = [ ... ];
        grid = new Slick.Grid($("#myGrid"), data, columns, options);
        grid.onSort = function(sortCol, sortAsc) {
         sortdir = sortAsc ? 1 : -1;
         sortcol = sortCol.field;
         // ?? 
     };
 })
A: 

You can write your own comparer to sort "data" with (see standard Array sorting examples). After that, tell the grid to rerender:

grid.invalidate();
grid.render();
Tin