VadimDez / ngx-filter-pipe

𝗩 Angular 5+ pipeline for array filtering.
https://vadimdez.github.io/ngx-filter-pipe
MIT License
146 stars 37 forks source link

Filter by anything #37

Open msholly opened 7 years ago

msholly commented 7 years ago

Thanks for your work on this library. I have some user data already loaded in the view, and I'd like to filter by anything that matches. Do I have to specify each field in a getUsers() style function from your examples, or can it just look at the whole record and return anything that matches.

Here's some example code.

"users":[
      {
         "id":1,
         "email":"email@domain.com",
         "fname":"User",
         "lname":"One",
         "department":2,
         "custom_fields":[
            {
               "id":1,
               "value":"ABC Company"
            },
            {
               "id":2,
               "value":"Designer"
            }
         ]
      },
      {
         "id":2,
         "email":"email2@domain.com",
         "fname":"User",
         "lname":"Two",
         "department":3,
         "custom_fields":[
            {
               "id":1,
               "value":"ABC Company"
            },
            {
               "id":2,
               "value":"President"
            }
         ]
      }
   ]
<input [(ngModel)]="searchTerm" value="searchTerm"></input>
<div *ngFor="let user of users | filterBy:searchTerm">
MurhafSousli commented 7 years ago

I have a list of contacts with a text input to filter the result, I would like to be able to filter result by contact name or phone number. Any updates on this?

VadimDez commented 7 years ago

@MurhafSousli use $or - https://github.com/VadimDez/ngx-filter-pipe#or-matching

ismendoza commented 7 years ago

@MurhafSousli No! your solution doesn't work!

  1. msholly doesn't want to filter by "one AND two" = "German AND English".
  2. msholly wants to filter by email OR fname OR lname in the same input text.
msholly commented 7 years ago

Another way to describe would be a wildcard search, without having to specify the keys to search. Since data could be user generated or dynamic, would be nice to just search no matter what.

dvalvarenga commented 6 years ago

@MurhafSousli I did it .

My register have Name and Number , but I created one field more : name : DAVID phone : + 1 (510) 760 7607 full : david + 1 (510) 760 7607 < --- I use this field to filter, so I've one textfield where I can write something like 'david' or '510' or '+1'......

Maybe it help you.

Abenezer commented 6 years ago

@dvalvarenga offcourse you can do that but it means modifing the data array, which might not be nice if your data came from service or used by other features. @VadimDez its best if the pipe did this itself, add an option to contacate fields ( may be array|filterBy:{term: searchTerm, fields: ['field1','field2']} )

mshollyintellicon commented 6 years ago

Didn't AngularJS <v1.6 look through all available fields, and you had to expressly tell it to only search certain fields? However I'm sure performance-wise, that was a poor choice in old AngularJS.

But I did like @Abenezer suggestion, at least for my use case. Just a clean way to target fields, but also keep in mind that the data structure could be dynamic. So wildcarding or fully searching for any matches might be more widely helpful.

RobertThwaite commented 6 years ago

Just created a Pull request implementing Abenezer Suggestion. And ability to close this issue

anurag-aadi commented 6 years ago

the issue still open, the problem are really big :(

Oowaay commented 6 years ago

Any news on this feature ? I'm really interested :/

RobertThwaite commented 6 years ago

Not sure if vadimDez has seen the pull request. If not you can pull directly from that if your urgent.

anurag-aadi commented 6 years ago

i got the solutions, but its just a smart way :) put all your data in particular filed as with pipe divided and filter on that particular field you got the result :)