各位程序员大家好,
我的要求是在运行时在网格中添加一列或使用ui-grid动态添加.我能够使用按钮实现相同,但我想要的是覆盖图标的预定义功能,在用于排序的网格标题和一些预定义的任务(),我想在那里添加一个更多的功能
我的要求是在运行时在网格中添加一列或使用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之前有一个缩小的脚本,它不应该在那里.