سؤال

I have set up an ngTable and the following tableParams:

var selectedItems = []; $scope.tableParams = new ngTableParams({ page: 1, // show first page count: 5 // count per page }, { total: selectedItems.length, // length of data getData: function ($defer, params) { $defer.resolve(selectedItems.slice((params.page() - 1) * params.count(), params.page() * params.count())); } });

The content of "selectedItems" is updated via a $scope.$watch that monitors the users selection from another "screen" in the single page application. However, after the user makes their selection, the "count" property in the tableParams is being ignored and it is displaying all 15 rows with no pagination options.

هل كانت مفيدة؟

المحلول

I had similar issues with ngTable pagination and for those with the same problem the fix is to reference the ngTable $data scope within the ng-repeat directive (regardless of where/how you store the table data).

i.e. <tr ng-repeat="item in $data">

It appears that $defer.resolve() will assign table data (i.e. selectedItems) to the $data scope to observe model mutations - which is tricky since referencing selectedItems in ng-repeat still displays the data (just without pagination!).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top