AngularJs- ng-repeat: filtering

26 views
Skip to first unread message

Drew Skee

unread,
Nov 13, 2014, 1:46:01 PM11/13/14
to ang...@googlegroups.com

I have the following filter that works as it should on the “ACCOUNTNAME” column :

<tr ng-repeat="record in records |filter:paginate|filter:{ACCOUNTNUMBER:searchText}">

 

I also have a ng-model /variable ‘seletcedCol’ that gets the selected Column and is displayed with the correct data using {{selectedCol}}.

 

Here are the two models I have for the searchText and selectedCol.

<select id="selectedCol" ng-model="selectedCol"  ng-options="column for column in columns|orderBy:'toString()'"><option value="">--Select One--</option></select>

                    <input id="searchText" ng-model="searchText" type="text" placeholder="Search" />

 

I’m trying to use selectedCol in the filter instead of the column name(hardcoded) , but it doesn’t work correctly…any idea why this wouldn’t work?

<tr ng-repeat="record in records |filter:paginate|filter:{selectedCol:searchText}"> 

Sander Elias

unread,
Nov 14, 2014, 12:39:43 AM11/14/14
to ang...@googlegroups.com

Hi Drew,

Create an object by hand and use that.

add this to your select ng-change="filterOn={};filterOn[selectedCol]= searchText}"
and change the filter to use the filterOn object.

Regards
Sander

Drew Skee

unread,
Nov 14, 2014, 10:53:23 AM11/14/14
to ang...@googlegroups.com
Hi Sander

I think this is the approach I was going to take where the ng-change= filterOn  calls a function that I create in my main apps page, right? For the part where you say "add this to your select ng-change='filterOn={};filterOn[selectedCol]= searchText}'" should my ng-change call the function simply like " ng-change=filterOn()" or should it be ng-change="filterOn={};filterOn{[selectedCol]= searchText}". To be sure I'm understanding this correctly, the filtering happens when the function is executed returning the array of filtered records, right?...I will create and post the function that I'm thinking of. I appreciate your reply.

Thanks


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/-MSRsjpygnM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Nov 14, 2014, 11:09:51 AM11/14/14
to ang...@googlegroups.com
Hi Drew,

I think you got it right, euhm, maybe ;)
If in doubt, build a plunk out of your problem!

Regards
Sander
Reply all
Reply to author
Forward
0 new messages