0
votes

I have the following scenario : I get data for UI grid and display it with ability to toggle header filters. Sometime later I need to request data again and also be able to toggle filters. My code only works the first time. After I request data again ( basically recreate what I do to initially setup the table) the filter no longer works. I have created a plunker that illustrates this http://plnkr.co/edit/KQbkGZQnjxCFTrS4Elgh?p=preview: click toggle Filtering button - see the filters ok. Then press: request data again - the filter no longer works. My suspicion is onRegisterApi method gets called only once although I'm not sure if that's it. Any help appreciated.

 $scope.toggleFiltering = function(){
    $scope.gridOptions.enableFiltering = !$scope.gridOptions.enableFiltering;
    $scope.gridApi.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
  };
2

2 Answers

2
votes

You don't have to re-initialize the gridOptions when request data again. Removing that from your plnkr fixed it. So your requestDataAgain function will look like this:

$scope.requestDataAgain = function(){

  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
  $scope.gridOptions.data = data;
  $scope.gridOptions.data[0].age = -10;

  data.forEach( function addDates( row, index ){
    row.mixedDate = new Date();
    row.mixedDate.setDate(today.getDate() + ( index % 14 ) );
    row.gender = row.gender==='male' ? '1' : '2';
  });

});

};

Here is the updated plnkr.

1
votes

See if this works for you. You're calling again $scope.gridOptions on $scope.requestDataAgain and it's not necessary.

  $scope.requestDataAgain = function(){
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
.success(function(data) {
  $scope.gridOptions.data = data;
  $scope.gridOptions.data[0].age = -5;

  data.forEach( function addDates( row, index ){
    row.mixedDate = new Date();
    row.mixedDate.setDate(today.getDate() + ( index % 14 ) );
    row.gender = row.gender==='male' ? '1' : '2';
  });

});

};

Updated plnkr