var app = angular.module('app', ['ngTouch', 'ui.grid', 'ui.grid.moveColumns']);
app.controller('MainCtrl', ['$scope', '$timeout', function ($scope, $timeout) {
$scope.gridOptions = {
enableSorting: true
};
var colCount = 500;
var rowCount = 500;
$scope.gridOptions.columnDefs = [];
$timeout( function() {
for (var colIndex = 0; colIndex < colCount; colIndex++) {
$scope.gridOptions.columnDefs.push({
name: 'col' + colIndex,
width: Math.floor(Math.random() * (120 - 50 + 1)) + 50
});
}
});
var data = [];
$timeout( function() {
for (var rowIndex = 0; rowIndex < rowCount; rowIndex++) {
var row = {};
for (var colIndex = 0; colIndex < colCount; colIndex++) {
row['col' + colIndex] = 'r' + rowIndex + 'c' + colIndex;
}
data.push(row);
}
});
$scope.gridOptions.data = data;
$scope.$on("destroy", function(){
$timeout.cancel();
});
}]);
.grid {
width: 500px;
height: 400px;
}
<!doctype html>
<html ng-app="app">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular-touch.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/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.js"></script>
<link rel="stylesheet" href="http://ui-grid.info/release/ui-grid.css" type="text/css">
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div ng-controller="MainCtrl">
<strong>{{ gridOptions.columnDefs.length | number }} Columns with Random Widths</strong>
<br>
<br>
<div id="grid1" ui-grid="gridOptions" class="grid" ui-grid-move-columns></div>
</div>
<script src="app.js"></script>
</body>
</html>