Despite the fact that there is already an accepted answer that undoubtedly solved the initial question, I wanted to point out a general error in stackoverflow when processing the Slickgrid subscription method.
Imagine that our grid is in a variable called a "grid", as in most other examples. This happens in most accepted and / or pending responses:
dataView.onRowsChanged.subscribe(function(e,args) { grid.invalidateRows(args.rows); grid.render(); });
or
grid.onSort.subscribe(function(e, args){ var cols = args.sortCols; data.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; }) grid.invalidate() grid.render() })
Do these examples perform as intended? Yes, they ... in certain circumstances.
Imagine a function that adds Slickgrid to the Slickgrids list:
var m_grids = [] function anyName(){ var grid;
So, what happens now when we try to call any subscription function, while the subscription function contains a variable grid? It simply affects the last assigned grid, regardless of which subscription was made to them. The correct way to sign these functions is with the args parameter:
dataView.onRowsChanged.subscribe(function(e,args) { args.grid.invalidateRows(args.rows); args.grid.render(); });
or
grid.onSort.subscribe(function(e, args){ var cols = args.sortCols; args.grid.getData().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; }) args.grid.invalidate() args.grid.render() })
This may be a minor case, as this usually requires more than one Slickgrid, but why not make a mistake if we can do this very easily :)