Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by substring #238

Closed
AlJohri opened this issue Nov 10, 2014 · 3 comments
Closed

Filter by substring #238

AlJohri opened this issue Nov 10, 2014 · 3 comments
Assignees

Comments

@AlJohri
Copy link

AlJohri commented Nov 10, 2014

I read through the client side filtering code here https://github.com/jmdobry/angular-data/blob/master/src/datastore/index.js#L12 and can't find any option that allows for filtering by substring.

I request data from my api that contains a substring like so:
Listing.findAll({message__contains: "bike"});
and I would like to get this data again via angular-data's filter.

var listings = Listing.filter({ where: {message:{'__something__':'bike'}} });

where __something__ would check listing.message.indexOf(parameter).

Is something like this within the purview of this project?


As a temporarily alternative I see your solution here: #76 (comment) but would like to find a better solution.

EDIT: just read the alternative more carefully - it seems as though its still not possible to do what I'd like

If you have no control over the how the server handles the params sent by findAll, then angular-data provides the implementable queryTransform function. In addition, you can override the function that filter uses internally to figure out how to pull the correct subset out of the data store.

@jmdobry
Copy link
Member

jmdobry commented Nov 10, 2014

Yeah, it would probably make sense to add something like this.

@jmdobry jmdobry self-assigned this Nov 19, 2014
@jmdobry
Copy link
Member

jmdobry commented Nov 19, 2014

Now the in, notIn, |in and |notIn operators will work on strings. Example:

DS.filter('user', {
  where: {
    name: {
      // get all users where
      // user.name.indexOf('John') !== -1
      'in': 'John'
    }
  }
});

@AlJohri
Copy link
Author

AlJohri commented Nov 20, 2014

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants