2015-04-16 51 views
3

我必須顯示兩種類型的gridOptions,而不使用兩個網格試圖更改gridOptions動態不工作(一次工作)。動態更改角度UI網格選項

工作示例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

看到它是 –

回答

5

基本上需要使用angular.copy()而分配columnDef到電網,這個克隆的陣列,並將其設置到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); 
} 

Working Plunkr

+0

感謝工作http://plnkr.co/edit/CvqzuRM4DzwxlbMs0kky?p=preview你,如果你知道,請幫助HTTP:/ /stackoverflow.com/questions/29643310/change-the-menuitem-icon-in-angular-ui-gird – vamsikrishnamannem