1

I have a complex set of filters on an ng-repeat. I'm trying to get the count of the data set as it is filtered via each select list.

Here's my ng-repeat:

		<div class="trials-item {{class}}" ng-repeat="data in dataObject | byCountry : selectRegion | byRegion : selectState | byCity : selectCity | filterBy:['Phase']: selectPhase | filterBy:['Compound']: selectCompound | filterBy:['TherapeuticArea', 'TherapeuticArea_2',]: selectTherapy : 'strict' | unique: 'Id' | orderBy:'Phase' : reverse track by $index " ng-class="{'open':$index == selectedRow}" id="anchor-{{$index}}" >

Trying to use {{ data.length }} doesn't work. I've tried to use some of the solutions detailed in this post: How to display length of filtered ng-repeat data , but they all deal with a much simpler set of filters, and if they would work with my filter set above, I must not be getting the syntax/order correct.

1 Answer 1

3

You only have to assign a variable towards the filtered dataObject, and make sure to enclose the assignment expression with a parenthesis after the in key word and before the track key word.

<div class="trials-item {{class}}" ng-repeat="data in (filteredData = (dataObject | byCountry : selectRegion | byRegion : selectState | byCity : selectCity | filterBy:['Phase']: selectPhase | filterBy:['Compound']: selectCompound | filterBy:['TherapeuticArea', 'TherapeuticArea_2',]: selectTherapy : 'strict' | unique: 'Id' | orderBy:'Phase' : reverse)) track by $index " ng-class="{'open':$index == selectedRow}" id="anchor-{{$index}}" ></div>
Result: {{ filteredData.length }}

Update

In case you're having problems with the scope of your variables, create an object $scope variable that stores the filtered data.

Javascript

$scope.filtered = {};

HTML

<div class="trials-item {{class}}" ng-repeat="data in (filtered.data = (dataObject | byCountry : selectRegion | byRegion : selectState | byCity : selectCity | filterBy:['Phase']: selectPhase | filterBy:['Compound']: selectCompound | filterBy:['TherapeuticArea', 'TherapeuticArea_2',]: selectTherapy : 'strict' | unique: 'Id' | orderBy:'Phase' : reverse)) track by $index " ng-class="{'open':$index == selectedRow}" id="anchor-{{$index}}" ></div>
Result: {{ filtered.data.length }}
Sign up to request clarification or add additional context in comments.

4 Comments

This doesn't bomb the query, but it also doesn't give me a value returned on the filteredData.length output.
If I may ask, is the result of the filteredData an object or an array?
If filteredData is undefined, then surely the ng-repeat result should be empty as well. If that's the case then the problem isn't in the assignment but in the filters.
What's the scope of filteredData - ie, what would I use in the console.log to get the value/type? I am getting a data set back, so it must have some value. I suspect I have the wrong $scope for logging. Was using console.log($scope.filteredData);

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.