angularjsangularjs-directivedirpagination

How to get an dir-paginate filtered result reference


I am using angularjs v1.2.9 in my project. I use dir-pagination to display a list of items in my web app. A few filters are also used to sort the list dynamically. Is there any way for me to get the dynamically sorted list in my controller? I tried the solutions given here. But they dont seem to work with dir-pagination.

<tr dir-paginate="person in contacts|filter:searchText|filter:groups|orderBy:['name','email'] | itemsPerPage : 10"

Solution

  • You could use a function to return filtered results when you need them.

    function getFilteredResults() {
        return $scope.$eval("person in contacts|filter:searchText|filter:groups|orderBy:['name','email']");
    }
    

    And if you just want the filtered results, and not the paginated results you could.

    <dir-paginate="person in filteredPersons = (contacts|filter:searchText|filter:groups|orderBy:['name','email']) | itemsPerPage : 10">
    

    And if you need a page of the filtered results you could handle that in your controller like this.

    function getFilteredPersonsOnPage() {
        var end;
        var start;
        var itemsPerPage = parseInt($scope.queryState.pageSize) || 999;
        start = ($scope.currentPage - 1) * itemsPerPage;
        end = start + itemsPerPage;
        return $scope.filteredPersons.slice(start, end);
    }