Upgrading from ng-grid 2.0.x to ui-grid 3.0
Directive name has changed from ng-grid to ui-grid.
Before:
<div ng-grid="{ data: data }"></div>
angular.module('yourModule', ['ngGrid'];
After:
<div ui-grid="{ data: data }"></div>
angular.module('yourModule', ['ui.grid'];
ColumnDefs are now always watched via $watchCollection.
Before:
$scope.myColDefs = {[...]};
$scope.gridOptions.columnDefs = 'myColDefs'
After:
$scope.gridOptions.columnDefs = $scope.myColDefs = [...];
or
$scope.gridOptions.columnDefs = [...];
Before:
$scope.gridOptions = {
columnDefs: [
{ displayName: 'Edit' }
],
data: myData
};
After:
$scope.gridOptions = {
columnDefs: [
{ name: 'edit', displayName: 'Edit' }
],
data: myData
};
You can no longer access data or functions directly on the parent scope. You must use grid.appScope to get a reference to the parent scope
Before:
$scope.gridOptions = {
columnDefs = [
{ name: 'edit', displayName: 'Edit', cellTemplate: '<button ng-click="edit(row.entity)" >Edit</button>' }
],
data: myData
};
$scope.edit = function( entity ) {
...some custom function using entity...
};
<div ng-grid="gridOptions" ></div>
After:
$scope.gridScope = $scope;
$scope.gridOptions = {
columnDefs = [
{ name: 'edit', displayName: 'Edit', cellTemplate: '<button ng-click="grid.appScope.edit(row.entity)" >Edit</button>' }
],
data: myData
};
$scope.edit = function( entity ) {
...some custom function using entity...
};
Refer to the tutorials and API documentation at http://ui-grid.info/docs/ for more detail, an example provided below is column resizing. The plugins are available in the base javascript, using them requires only including the appropriate directive in the grid declaration:
After:
<div ui-grid="gridOptions" ui-grid-resize-columns ></div>