加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何使用ui-grid在网格中在运行时添加列

发布时间:2020-12-17 10:22:27 所属栏目:安全 来源:网络整理
导读:各位程序员大家好, 我的要求是在运行时在网格中添加一列或使用ui-grid动态添加.我能够使用按钮实现相同,但我想要的是覆盖图标的预定义功能,在用于排序的网格标题和一些预定义的任务(),我想在那里添加一个更多的功能 var app = angular.module('app',['ngAnim
各位程序员大家好,
我的要求是在运行时在网格中添加一列或使用ui-grid动态添加.我能够使用按钮实现相同,但我想要的是覆盖图标的预定义功能,在用于排序的网格标题和一些预定义的任务(),我想在那里添加一个更多的功能
var app = angular.module('app',['ngAnimate','ui.grid']);

app.controller('MainCtrl',['$scope','$http','uiGridConstants',function ($scope,$http,uiGridConstants) {
  $scope.columns = [{ field: 'name' },{ field: 'gender' }];
  $scope.gridOptions = {
    enableSorting: true,columnDefs: $scope.columns,onRegisterApi: function(gridApi) {
      $scope.gridApi = gridApi;
    }
  };
  
 
  
  $scope.add = function() {
    $scope.columns.push({ field: 'company',enableSorting: false });
  }

 

  $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
    .success(function(data) {
      $scope.gridOptions.data = data;
    });
}]);
.grid {
  width: 500px;
  height: 250px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!doctype html>
<html ng-app="app">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-touch.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-animate.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/csv.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/pdfmake.js"></script>
    <script src="http://ui-grid.info/docs/grunt-scripts/vfs_fonts.js"></script>
    <script src="http://ui-grid.info/release/ui-grid-unstable.js"></script>
    <link rel="stylesheet" href="http://ui-grid.info/release/ui-grid-unstable.css" type="text/css">
    <link rel="stylesheet" href="main.css" type="text/css">
  </head>
  <body>

<div ng-controller="MainCtrl">
  Try clicking the Add button to add the company column.
  <br>
  <br>
  <button id="button_add" class="btn" ng-click="add()">Add</button>
  <div id="grid1" ui-grid="gridOptions" class="grid"></div>
</div>


    <script src="app.js"></script>
  </body>
</html>

在那里添加一列

您可以在add方法中使用$watch:
$scope.add = function() {

    $scope.columns.push({ field: 'company',enableSorting: false });

    $scope.$watch('columns',function(newVal,oldVal){
         console.log('added');
    },true);

}

我注意到你在文档的doctype之前有一个缩小的脚本,它不应该在那里.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读