user3421339 user3421339 - 27 days ago 26
AngularJS Question

UIGRID: Changing cellFilter in columnDefs is not well updated

I need to dynamically change the decimal precision of a column.
I have tried different approaches and non of them worked.

I did a quick example in Plunker in which there is a button to swap data. They have different data and different columnDefs: one has 3 decimals and the other 4.
You can see there that the first rows maintain the first format.

I'm using notifyDataChange in gridApi but is not working for this kind of change:

$scope.gridApi.core.notifyDataChange( this.uiGridConstants.dataChange.ALL );


This is a problem for me because in my case I want to keep the same data but dynamically change the decimal precision of a column.

Does anybody knows how to refresh/reload that new columnDefs configuration?
I would really appretiate it!

Answer

Sadly it seems none of the usual methods to refresh/update the grid will work with this use case.

I managed to make it work though by deleting all rows and then recreating them after a $timeout.

I updated your plunker here.

The main edit is as follows:

 $scope.swapData = function() { 
    $scope.gridOpts.data = []{
    $timeout(function() {
      if (!$scope.isData2) { 
        $scope.gridOpts.data = data2;
        $scope.gridOpts.columnDefs = columnDefs2;
      }
      else {
        $scope.gridOpts.data = data1;
        $scope.gridOpts.columnDefs = columnDefs1;
      }
      $scope.isData2 = !$scope.isData2;  
    });
  };
Comments