1

I have a ng-repeat to create table:

ng-repeat="equipment in equipments | filter: equipmentFilter | dateFilter: dateStart: dateEnd | pageFilter: currentPage * pageSize | limitTo: pageSize"

I need to get:

(equipments | dateFilter: dateStart: dateEnd | filter: equipmentFilter).length

to update number of total page in paging feature. I've tried:

ng-init="equipmentsForPaging = (equipments | dateFilter: dateStart: dateEnd | filter: equipmentFilter)"

But it isn't working at all, also I don't think using ng-init is a good idea. So are there anyway to do this in javascript?

1 Answer 1

1

There are $filter, you can inject and use it in your controller.

But if you use that, you will re use filter so there are 2 filter treatments (2 loops) so in my opinion it's not good idea.

You already got that filtered array in your view, you just need to assign it to a variable, in the ng-repeat, and use parenthesis to distinct your needed array:

ng-repeat="equipment in filtered = (equipments | filter: equipmentFilter | dateFilter: dateStart: dateEnd) | pageFilter: currentPage * pageSize | limitTo: pageSize"

then you can just use {{filtered.length}}

Sign up to request clarification or add additional context in comments.

2 Comments

Wow, I have no idea it's that easy. But how can I inject the 'dateFilter' in javascript since it got 2 argument? And does $filter modified the array input?
It'a a filter, created by app.filter(), eg: .filter('dateFilter', function() { return function( items, fromDate, toDate ) {...}); you can use $filter('dateFilter')(array, fromDate, toDate)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.