Having encountered an unusual issue with ng-table. Here is a snippet of code from my controller:
this.category = "Open";
this.category = ["Open", "Accepted", "Rejected"];
this.dataItems = [];
var _this = this;
this.$scope.$watch("vm.category", function(category) {
_this.dataItems.length = 0; // Clearing items in the array
svc.getApplications(category).then(
function(okResult) {
angular.copy(okResult.data, _this.dataItems);
_this.tableParams = new NgTableParams(
{
page: 1,
count: 5,
sorting: {
applicationDate: 'desc'
}
},
{
total: _this.dataItems.length,
getData: function ($defer, params) {
var filtered = params.filter() ? _this.$filter('filter')(_this.dataItems, _this.filter) : _this.dataItems;
var ordered = params.sorting() ? _this.$filter('orderBy')(filtered, params.orderBy()) : filtered;
params.total(ordered.length);
if (params.total() < (params.page() - 1) * params.count()) {
params.page(1);
}
$defer.resolve(ordered.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
}
});
I have omitted some parts of the code for brevity. $scope
, $filter
, NgTableParams
are all injected.
The UI has a dropdown like this:
<select id="cbCategory" class="form-control" data-ng-model="vm.category" data-ng-options="category for category in vm.categories"></select>
And the ng-table appears as follows:
<table class="table table-striped table-hover" id="tb1" data-ng-table="vm.tableParams">
<tbody>
<tr data-ng-repeat="item in $data">
<td data-title="'Email'" data-filter="{ email: 'text' }" data-sortable="'email'">{{item.applicant.email}}</td>
<!-- more... -->
</tr>
</tbody>
</table>
The problem I am facing: The table initially renders correctly. However, when I change the selection on the category dropdown, the getApplications
call is made and
_this.tableParams = new NgTableParams
is executed (I confirmed through debugging that the service call runs without error). Yet, getData
does not seem to trigger, resulting in no changes on the UI. I have used ng-table extensively but have not encountered this particular rerendering scenario before. What could I be overlooking?
Just to clarify, there is controllerAs: vm
somewhere in the code.