in controller
var app = angular.module('app', ['ngTouch', 'ui.grid']);
app.controller('MainCtrl', ['$scope', function ($scope) {
$scope.addData = function() {
var n = $scope.gridOpts.data.length + 1;
$scope.gridOpts.data.push({
"firstName": "New " + n,
"lastName": "Person " + n,
"company": "abc",
"employed": true,
"gender": "male"
});
};
var columnDefs1 = [
{ name: 'firstName' },
{ name: 'lastName' },
{ name: 'company' },
{ name: 'gender' }
];
var data1 = [
{
"firstName": "Cox",
"lastName": "Carney",
"company": "Enormo",
"gender": "male"
},
{
"firstName": "Lorraine",
"lastName": "Wise",
"company": "Comveyer",
"gender": "female"
},
{
"firstName": "Nancy",
"lastName": "Waters",
"company": "Fuelton",
"gender": "female"
},
{
"firstName": "Misty",
"lastName": "Oneill",
"company": "Letpro",
"gender": "female"
}
];
$scope.gridOpts = {
columnDefs: columnDefs1,
data: data1
};
}]);
in html
<body>
<div ng-controller="MainCtrl">
<button type="button" id="addData" class="btn btn-success" ng-click="addData()">Add Data</button>
<div id="grid1" ui-grid="gridOpts" class="grid"></div>
</div>