Dynamically Change the Grid Options in angular ui.grid

雨燕双飞 提交于 2019-12-21 02:53:09

问题


I have to show two types of gridOptions without using two grid's trying to change the gridOptions dynamically not working(one time working).

working example 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);
 }

回答1:


Basically you need to use angular.copy() while assigning columnDef to grid, which clones the array and set it to the gridOptions.

Code

 $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);
 }

Working Plunkr



来源:https://stackoverflow.com/questions/29678403/dynamically-change-the-grid-options-in-angular-ui-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!