以角度ui.grid动态更改网格选项

vam*_*nem 3 angularjs ng-grid angular-ui-grid

我必须显示两种类型的gridOptions而不使用两个网格尝试动态更改gridOptions不工作(一次工作).

工作示例http://plnkr.co/edit/4QKGIB?p=preview.

$scope.grid1=function(){
   $scope.gridOptions = $scope.gridOptions1;
   $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
 }
 $scope.grid2=function(){
   $scope.gridOptions = $scope.gridOptions2;
   $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
 }
Run Code Online (Sandbox Code Playgroud)

Pan*_*kar 5

基本上你需要angular.copy()在将columnDef指定给grid时使用,它会克隆数组并将其设置为gridOptions.

 $scope.gridOptions = angular.copy($scope.gridOptions1);
 $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
 .success(function(data) {
   $scope.gridOptions1.data = data;
   $scope.gridOptions2.data = data;
   $scope.grid1();
 });
 $scope.grid1=function(){
   $scope.gridOptions = angular.copy($scope.gridOptions1);
   $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
 }
 $scope.grid2=function(){
   $scope.gridOptions = angular.copy($scope.gridOptions2);
   $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.ALL);
 }
Run Code Online (Sandbox Code Playgroud)

工作Plunkr