How to disable sorting of multiple columns in ui-grid

I have a client who specifically dislikes the numbers following in the column headers when sorting. This is based on the multi-level UI-Grid interface, which gives each column a numbered priority. Is there a way to disable multi-sorting to remove these numbers? I still want the sort to activate, but only one column at a time. Thanks.

+4
source share
2 answers

I had this problem. If you look carefully in the ui0grid.js code, you will see that at the moment there is no possibility of forwarding it. The ui-grid authors claim that they would welcome a request for such a function to this thread

, ; -)

, sortColumns sortChanged.

- :

$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();
             }
         }
    });
};

ui-grid 3.0.0.

+2

, Grid.prototype.sortColumn, ui-grid.js.

self.resetColumnSorting(column);
column.sort.priority = undefined;

..

0

Source: https://habr.com/ru/post/1616247/


All Articles