I am using ngTable to display data from server. When i load data for the first time, ngTable is created with data form server. But when a fetch data second time with others search criterias. The ngTable is not refresh at this time even if data are retrieved. I have to click on pagination to get data refresh.
<div class="row custom-margin" ng-controller="ListCtlr" ng-init="initData()">
<form class="form-inline" role="form" id="formId" name="formId">
<div class="form-group">
<label for="searchInput">Data to search</label>
<input ng-model="searchInput" placeholder="Enter term to search">
</div>
<button type="submitSearch" class="btn btn-primary" ng-click="search()">Go</button>
</form>
<table ng-table="tableParams" class="table ng-table-responsive">
<thead>
<tr class="info">
<th class="centertext">Name</th>
<th class="centertext">Age</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="person in $data">
<td data-title="'Name'">{{person.name}}</td>
<td data-title="'Age'">{{person.age}}</td>
</tr>
</tbody>
</table>
<script type="text/ng-template" id="custom/pager">
<ul class="pager ng-cloak">
<li ng-repeat="page in pages"
ng-class="{'disabled': !page.active, 'previous': page.type == 'prev', 'next': page.type == 'next'}"
ng-show="page.type == 'prev' || page.type == 'next'" ng-switch="page.type">
<a ng-switch-when="prev" ng-click="params.page(page.number)" href="">« Previous</a>
<a ng-switch-when="next" ng-click="params.page(page.number)" href="">Next »</a>
</li>
<li>
<div class="btn-group">
<button type="button" ng-class="{'active':params.count() == 10}" ng-click="params.count(10)" class="btn btn-default">10</button>
<button type="button" ng-class="{'active':params.count() == 25}" ng-click="params.count(25)" class="btn btn-default">25</button>
<button type="button" ng-class="{'active':params.count() == 50}" ng-click="params.count(50)" class="btn btn-default">50</button>
<button type="button" ng-class="{'active':params.count() == 100}" ng-click="params.count(100)" class="btn btn-default">100</button>
</div>
</li>
</ul>
</script>
</div>
This is the controller:
function ListCtlr($scope, $http, $location,$filter,ngTableParams) {
$scope.formId = {searchInput: ''};
$scope.search = function () {
var url='server/search/'+this.searchInput;
$http.get(url)
.success(function (data) {
$scope.persons = data;
$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
total: data.length, // length of data
getData: function($defer, params) {
$defer.resolve(data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
})
.error(function(data){
$scope.error = data;
});
};
}
When i fetch data for the first time, ngTable displays with data coming from the server. But if send another request to the server the ngTable is not updated. Data are correctly retrieved. But Data are updated when i click on the button params.count(25). What to do to refresh ngTable after success data retrieved ?