var app = angular.module("myApp", ['ui.grid']);
function ctrl($scope) {
$scope.myData = {
data: "listing",
columnDefs: [{
field: "id",
displayName: "ID"
}, {
field: "name",
displayName: "Name"
}, {
field: "firstname",
displayName: "First Name"
}, {
field: "contacts",
displayName: "Contacts",
cellTemplate: "<div class='ui-grid-cell-contents'><div ng-repeat='field in COL_FIELD'>{{field.id}} - {{field.type}}- {{field.value}}</div></div>"
}, ],
rowHeight: 100
}
$scope.listing = [{
"id": "0",
"name": "My name",
"firstname": "My first Name",
"contacts": [{
"id": "0",
"type": "phone",
"value": "0574869345"
}, {
"id": "1",
"type": "email",
"value": "myEmail@mail.com"
}]
}, {
"id": "1",
"name": "My name One",
"firstname": "My first Name One",
"contacts": [{
"id": "2",
"type": "phone",
"value": "0574444444"
}, {
"id": "3",
"type": "email",
"value": "myEmailOne@mail.com"
}]
}];
$scope.count = 0;
$scope.switch = function() {
if ($scope.count % 2 == 0) {
$scope.listing = [{
"id": "0",
"name": "My name",
"firstname": "My first Name",
"contacts": [{
"id": "0",
"type": "phone",
"value": "0574869345"
}, {
"id": "1",
"type": "email",
"value": "myEmail@mail.com"
}]
}, {
"id": "1",
"name": "My name One",
"firstname": "My first Name One",
"contacts": [{
"id": "2",
"type": "phone",
"value": "0574444444"
}, {
"id": "3",
"type": "email",
"value": "myEmailOne@mail.com"
}]
}];
} else {
$scope.listing = [{
"id": "2",
"name": "My name Two",
"firstname": "My first Name Two",
"contacts": [{
"id": "4",
"type": "phone",
"value": "0888888888"
}, {
"id": "5",
"type": "email",
"value": "myEmailTwo@mail.com"
}]
}, {
"id": "3",
"name": "My name Three",
"firstname": "My first Name Three",
"contacts": [{
"id": "6",
"type": "phone",
"value": "022222222"
}, {
"id": "7",
"type": "email",
"value": "myEmailThree@mail.com"
}]
}];
}
$scope.count++;
console.log('switched!');
};
}
.uiGridTable: {
height: 600px;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdn.rawgit.com/angular-ui/bower-ui-grid/master/ui-grid.min.js"></script>
<link href="https://cdn.rawgit.com/angular-ui/bower-ui-grid/master/ui-grid.min.css" rel="stylesheet" />
<div ng-app="myApp" ng-controller="ctrl">
<button type="button" ng-click="switch();">Switch</button>
<div ui-grid="myData" class="uiGridTable"></div>
</div>