Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Sorting

Marcelo Sauerbrunn Portugal edited this page Jun 11, 2018 · 1 revision

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! 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(a,b){
        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: "*", sortFn: myAwesomeSortFn },
                                        { field: 'age', cellClass: 'ageCell', headerClass: 'ageHeader', width "**"}]
    };
Clone this wiki locally