Cristian C.
Cristian C.

Reputation: 137

Sencha Touch 2: How to FIlter on a Association's Store?

I have an issue trying to filter the results of an association. I have a list of categories with many subcategories. I'm using MVC architecture. So, here is an example what I'm trying to do:

var subcategories = category.subcategories();

subcategories.filter("title", "some text");
subcategories.each( function (item) { console.log(item.get('title')); } );

Some how the filter is not applying. It always return the original store, same amount of records, etc.

I'm also doing this:

var subcategories = category.subcategories();

subcategories.filterBy(function(item) {
   console.log( item );
   return (item.get('title') == 'some text');
});

But the console.log it's not running even once! The store is full of records, I've cehcked that

Any ideas? Am I doing something wrong? Thanks

Upvotes: 2

Views: 592

Answers (2)

Viswa
Viswa

Reputation: 3211

This may be a late answer, but it will help many people who are searching solution for the same problem.

The key is to calling setRemoteFilter(false) on Association's Store.

var products = user.products();
products.setRemoteFilter(false); // without this line, filter on Association's Store didn't work
var categorieFilter = new Ext.util.Filter({
    property: 'categories',
    value   : 'Electronic'
});
products.setFilters(categorieFilter);

Upvotes: 1

sha
sha

Reputation: 17860

Couple questions:

  1. What version of Sencha Touch are you using?

  2. When using associations in Sencha Touch you still need to do a lot of work by yourself. It's not completely automatic. For example you need to add all subcatagories manually to each category object. Are you doing this?

Upvotes: 1

Related Questions