2

I need to do some operation after re-sizing the column in ui-grid. I didn't find any column re-size event in ui-grid. Please provide a way to detect column re-size event in ui-grid.

1 Answer 1

2

First check your enableColumnResizing to be enabled.

enableColumnResizing: true

Then you might want to use a watcher like this:

$scope.$watch('gridOptions.$gridScope.isColumnResizing', 
    function (newValue, oldValue) {        
        // do something here        
    });

Would be a good way to create a dedicated plugin for that purpose and plug it as a custom plugin then to your grid.

UPDATE: If above snippet isn't working:

I just found in their source code following part:

var publicApi = {
  events: {
    /**
     * @ngdoc event
     * @name columnSizeChanged
     * @eventOf  ui.grid.resizeColumns.api:PublicApi
     * @description raised when column is resized
     * <pre>
     *      gridApi.colResizable.on.columnSizeChanged(scope,function(colDef, deltaChange){})
     * </pre>
     * @param {object} colDef the column that was resized
     * @param {integer} delta of the column size change
     */
    colResizable: {
      columnSizeChanged: function (colDef, deltaChange) {
      }
    }
  }
};
grid.api.registerEventsFromObject(publicApi.events);

So, in your grid options object it'd be:

$scope.gridOptions = {
   enableColumnResizing: true,
   ...,
   onRegisterApi : function(gridApi) {            
     $scope.gridApi = gridApi; 
     $scope.gridApi.colResizable.on.columnSizeChanged($scope, function(colDef, deltaChange) {
       console.log('resized #############'); 
     });            
   }
};

And finally in html:

<div ui-grid="gridOptions" ...></div>
Sign up to request clarification or add additional context in comments.

5 Comments

Its not working. $watch is not calling when I resizing the columns in the grid.
@Aravinder did you check you have gridOptions field in your $scope with all other options defined for your grid?
In gridOptions, $gridScope variable is not there. How do I put $gridScope in to gridOptions
Thank you Meleshko. It worked with minor changes. Please update your answer with below code.$scope.gridOptions.onRegisterApi = function( gridApi ) { $scope.gridApi = gridApi; $scope.gridApi.colResizable.on.columnSizeChanged( $scope, function(colDef, deltaChange) { console.log('resized #############'); }); };
I needed to know the new column width. The event doesn't give you that, so to get the new width I did this (in TypeScript): gridApi.colResizable.on.columnSizeChanged(this.$scope, (colDef, deltaChange) => { var column = gridApi.grid.columns.filter(x => x.name == colDef.name)[0]; if (column) { console.log(``${colDef.name} resized by ${deltaChange} to ${column.width}``); } });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.