Skip to content
chmirenko edited this page Sep 28, 2016 · 6 revisions

Builtin sorting


We tried to make ng-grid do as good a job as sorting your data as possible by inspecting the data and attempting to "guess" what kind of data you have. All you have to do is click the header to sort! or shift+ click a header to do multi-column sorting! If you want to disable the feature you have two options:

  1. Turn off sorting on the entire grid:
    $scope.gridOptions = { data : myData,
                           enableSorting: false};
  1. Turn off sorting on a column by column basis (see Defining Columns)

If you have a custom sorting algorithm you can specify that in a column definition:

    var srirachaSauce = 1;
    var myAwesomeSortFn = function(a, b, rowA, rowB, direction){
        if (a == b) return 0;
        if (a < b) return -1;
        return srirachaSauce;
    };
    $scope.gridOptions = { data : myData,
                           columnDefs: [{ field: 'firstName', displayName: 'First Name', width: "*"},
                                        { field: 'lastName', displayName: 'Last Name', width: "*", sortingAlgorithm: myAwesomeSortFn },
                                        { field: 'age', cellClass: 'ageCell', headerClass: 'ageHeader', width "**"}]
    };
Clone this wiki locally