这个表格示例使用10000个记录的数据集。
演示如下:
- 绑定复杂的列属性 城市.地址。
- 同一字段可以在具有不同名称的表格中列出两次
- 使用字段而不是名称便于2.x 向后兼容
代码:
index.html
<!doctype html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-touch.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/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="/release/ui-grid.js"></script>
<script src="/release/ui-grid.css"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="MainCtrl">
<strong>Data Length:</strong> {{ gridOptions.data.length | number }}
<br>
<br>
<div id="grid1" ui-grid="gridOptions" class="grid"></div>
</div>
</body>
</html>
main.css
.grid {
width: 500px;
height: 450px;
}
app.js
var app = angular.module('app', ['ngTouch', 'ui.grid']);
app.controller('MainCtrl', ['$scope', '$http', '$q', function ($scope, $http, $q) {
$scope.gridOptions = {
};
$scope.gridOptions.columnDefs = [
{name:'id'},
{name:'name'},
{field:'age'}, // showing backwards compatibility with 2.x. you can use field in place of name
{name: 'address.city'},
{name: 'age again', field:'age'}
];
var canceler = $q.defer();
$http.get('/data/10000_complex.json', {timeout: canceler.promise})
.success(function(data) {
$scope.gridOptions.data = data;
});
$scope.$on('$destroy', function(){
canceler.resolve(); // Aborts the $http request if it isn't finished.
});
}]);
Demo
文章来源:西柚叨叨的个人博客