I have a client who specifically does not like the numbers next in the headers of the columns when doing a sort. This is rooted in UI-Grid's multi-sort, which gives each column a numbered priority. Is there a way to disable the multi-sort in order to remove those numbers? I still want to keep sorting activated, but only on one column at a time. Thanks.
I've had this problem myself. If you look carefully in the ui0grid.js code you'll see that there is (at this time) no option to diable it. The writers of ui-grid state that they would welcome a request for such a function in this thread
However, you want a fix, not a promise ;-)
You can spot how many sortColumns have been chosen in the sortChanged method.
Try something like this:
$scope.gridOptions.onRegisterApi = function(gridApi) {
    $scope.gridApi = gridApi;
    // Register a handler that is fired everytime someone changd the sort params.
    $scope.gridApi.core.on.sortChanged($scope, function(grid, sortColumns) {
        if (sortColumns.length > 1) {
            // We have more than one sort. Kill the first one.
            // If this works we'll only ever have 0, 1 or 2 sortColumns,
            // and only ever 2 for the lifetime of this method.
            var column = null;
            for (var j = 0; j < grid.columns.length; j++) {
                if (grid.columns[j].name === sortColumns[0].field) {
                    column = grid.columns[j];
                    break;
                }
             }
             if (column) {
                 sortColumns[1].sort.priority = 1; // have to do this otherwise the priority keeps going up.                           
                 column.unsort();
             }
         }
    });
};
This is against the 3.0.0 release of ui-grid.
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With