Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
like image 818
Shabin Muhammed Avatar asked Jan 29 '15 12:01

Shabin Muhammed


1 Answers

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);
}
like image 190
rich green Avatar answered Oct 20 '22 05:10

rich green