Results 1 to 2 of 2

Thread: Find a filtered Model in Store

  1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    1

    Default Find a filtered Model in Store

    I'm currently working on a project GXT+ reverse ajax.
    I need a basic list with possible to apply some filter. And this list will be updated in live by reverse ajax.
    So I did following steps in my code:
    Initialization:
    - Store store = new Store<MyModelData>();
    - store.addFilter(filter);
    To apply the filter:
    - store.applyFilters("property");
    To update by reverse ajax:
    - MyModelData model = store.findModel(id);
    - // update this model ...
    - store.update(model);

    Problem appears, when I want to update a model hidden (who has been filtered by the filter). Because we can't use findModel to return a ModelData hidden. Null will be returned in this case.
    So I had a look in gxt source code, here it is:

    Code:
    public void applyFilters(String property) {
        filterProperty = property;
        if (!filtersEnabled) {
          snapshot = all;
        }
    
        filtersEnabled = true;
        filtered = new ArrayList<M>();
        for (M items : snapshot) {
          if (!isFiltered(items, property)) {
            filtered.add(items);
          }
        }
        all = filtered;
    
        if (storeSorter != null) {
          applySort(false);
        }
    
        fireEvent(Filter, createStoreEvent());
      }
    
     public M findModel(M model) {
        for (M m : all) {
          if (equals(m, model)) {
            return m;
          }
        }
        return null;
      }
    applyFilters stocks the original list in snapshot and remove all model that should be hidden from the list all, but findModel researches only in the list all.
    At the same time, i don't see other method which could give me the "snapshot" list when I activate the filter.

    I could have a children class of Store to override the method I need, but I'm wondering, is there another way more native "GXT" to do this?

  2. #2
    Ext GWT Premium Member takayser's Avatar
    Join Date
    Oct 2008
    Location
    Lucerne, Switzerland
    Posts
    188

    Default

    nope, you have to extend.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •