//set columns
var columns = [
{
id: "mid",
name: "MID",
field: "mid",
cssClass: "cell-title",
sortable: true,
sorter:comparer
},
{
id: "id",
name: "ID",
field: "id",
cssClass: "cell-title",
sortable: true,
sorter:NumericSorter
},
var sortcol = "title";
var sortdir = 1;
var percentCompleteThreshold = 0;
var searchString = "";
this.grid.onSort = function(sortCol, sortAsc) {
sortdir = sortAsc ? 1 : -1;
sortcol = sortCol.field;
this.dataView.sort(sortCol.sorter);
this.grid.render();
}.bind( this );
function comparer(a,b) {
var x = a[sortcol], y = b[sortcol];
return sortdir * (x == y ? 0 : (x > y ? 1 : -1));
}
function NumericSorter(a, b) {
return sortdir * (a[sortcol]-b[sortcol]);
}
James source
share