How can I filter a dstore using the contains method?

435 views Asked by At

I have a dgrid populated with a dstore plain old Memory collection, that I am trying to filter using the 'contains' filter method. The store data looks something like this:

[
    {id:"25", users: ["13", "15"]},
    {id:"347", users: ["13"]},
    {id:"653", "users":["13", "17"]}
]

I want to retrieve all the records where a given user is in the users array. From my understanding, I was expecting to be able to set up a filter like new Filter().contains('users', '15'); and set that as the collection for the grid, leaving one row (id = '25') in this example. However, I am left with 0 rows. I have also tried providing a regular expression for the filter, instead of just value matching, like new Filter().contains('users', new RegExp('^15$')); however this doesn't filter out any rows.

I am using dojo v1.10.4, dgrid v1.0.0 and dstore v1.1.1. Here is a JSFiddle demonstrating my problem.

Am I doing something wrong?

Thanks.

1

There are 1 answers

1
Viliami On BEST ANSWER

You are storing users as an array, that is why you cannot use

new Filter().contains('users', '15');

If you want to use .contains than you will have to use it like this:

new Filter().contains('users', ['15']);

a.k.a you have to check by providing an array, not a string.