I have developed a custom directive for pagination that is compatible with grids throughout my website. On this particular page, there is a search feature that retrieves new data, and I am looking to update the pagination within my directive with this new set of data. Currently, I only have a link function in place.
Directive HTML
<table-pagination current-page="1" num-per-page="5" max-size="5" pagination-data="membersData" get-filtered-data="getFilteredData(membersData)" returned-paginated-data="returnedPaginatedData(data)"></table-pagination>
Directive.js
myAppModule.directive('tablePagination',
function () {
return {
templateUrl: 'Scripts/app/templates/tmplPagination.html',
restrict: 'E',
scope: {
currentPage: '=',
numPerPage: '=',
maxSize: '=',
paginationData: '=',
getFilteredData: '=',
filteredMembersData: '&'
},
link: function (scope, elem, attrs) {
scope.getFilteredData = function () {
$scope.$watch('currentPage + numPerPage', function () {
var begin = (($scope.currentPage - 1) * $scope.numPerPage), end = begin + $scope.numPerPage;
$scope.filteredMembersData = scope.paginationData.slice(begin, end);
});
}
},
controller: [
'$scope', function ($scope) {
}]
}
});
Pagination Template
<h4>Total number of records: {{membersData.length}}</h4>
<pagination ng-model="currentPage" total-items="membersData.length" max-size="maxSize" boundary-links="true"></pagination>
Contact Search Controller
$scope.returnedPaginatedData = function(data) {
$scope.filteredMembersData = data;
}
I need help passing $scope.filteredMembersData into my directive to refresh the pagination. Any suggestions on how to accomplish this?