How to Disable sorting on edit in angular ui grid?

250 views
Skip to first unread message

mportugal

unread,
Aug 14, 2016, 9:07:17 PM8/14/16
to UI-Grid Support

I am using angular ui-grid to display tabular data. I noticed that if a column is sorted and then if we edit the cell, the sorting gets kicked in and moves the row. I would like to disable sorting on cell edit, is there any way to do this.

I have done below for disable sorting after cellEdit but not working

$scope.gridOptions.onRegisterApi = function(gridApi) {
  //set gridApi on scope
  $scope.gridApi = gridApi;
  gridApi.edit.on.afterCellEdit($scope, function(rowEntity, colDef) {
    $scope.gridOptions.enableSorting = false;
    $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
 });
};

- @sandeepschoice

ksrd...@gmail.com

unread,
Feb 19, 2018, 2:32:48 AM2/19/18
to UI-Grid Support
Any updates on the above issue??

ksrd...@gmail.com

unread,
Feb 26, 2018, 3:54:55 AM2/26/18
to UI-Grid Support
I found a way to fix this problem by doing a simple hack.

The sorting is happening because of a call back function (registerDataChangeCallback) when there is notifyDataChange event gets fired and the processRowsCallback function is getting called and the processRowsCallback definition is as follows.

Grid.prototype.processRowsCallback = function processRowsCallback( grid ){
    grid.queueGridRefresh();
  };

Here Grid is a factory and the processRowsCallback functions is defined under the factory and its calling the grid.queueGridRefresh() and the sort is getting called and the sort happening just after the data changes in the grid.

So, I thought of overriding the prototype function processRowsCallBack by injecting the Grid factory to the factory which I have created (extendedGridFactory) and replicated the same function but having a condition checked, if the grid is not in editmode and calling grid.queueGridRefresh(); like the following.

app.factory('extendedGridFactory', ['Grid', '$rootScope', function (Grid, rootScope) {
var extendedGrid = Object.create(Grid);
extendedGrid.prototype.processRowsCallback = function processRowsCallback(grid) {
if (!rootScope.isInEditMode) {
grid.queueGridRefresh();
}
};
return extendedGrid;
}]);

Great, so far its works fine.

Let me know if you people finding any problem with this code. :)
Reply all
Reply to author
Forward
0 new messages