在 angular ui.grid 中动态更改网格选项 [英] Dynamically Change the Grid Options in angular ui.grid

查看:40
本文介绍了在 angular ui.grid 中动态更改网格选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在不使用两个网格的情况下显示两种类型的 gridOptions 试图动态更改 gridOptions 不起作用(一次工作).

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

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

推荐答案

基本上你需要使用 angular.copy() 同时将 columnDef 分配给 grid,它会克隆数组并将其设置为 angular.copy()代码>网格选项.

Basically you need to use angular.copy() while assigning columnDef to grid, which clones the array and set it to the 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);
 }

工作 Plunkr

这篇关于在 angular ui.grid 中动态更改网格选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆