Results 1 to 3 of 3

Thread: Changed behavior of Ext.data.Store.filterBy method, not matching the docs

  1. #1
    Sencha Premium Member
    Join Date
    Apr 2011
    Location
    Ukraine, Kyiv
    Posts
    28

    Wink Changed behavior of Ext.data.Store.filterBy method, not matching the docs

    Method Ext.data.Store#filterBy changed its behaviour from times of 4th version of ExtJS, but preserves the same signature and the identical method documentation.
    Below is the excerpt from documentation of the method and method codebase-screenshot, showing the difference.

    Filters by a function. The specified function will be called for each
    Record in this Store. If the function returns `true` the Record is included,
    otherwise it is filtered out.



    filterBy.jpg


    Main problem for the changes which were done in ExtJS 5+ versions (including 7th) that filterBy method each time creates and adds a new filter to filters collection, thus its behavior differs from the one described in documentation - method depends on its previous calls. Thus, a new version of filterBy method, being called at least once adds a filter and the next time filtering result of using filterBy method will be depended not only on the last provided function parameter but also on the previous calls of this method (each call -> adds a filter).
    But based on the documentation to the method and previous behavior each call of filterFn should be independent.

    For instance, the simplest example, having data set of:
    "A"
    "B"
    "ABC"
    and calling 3 times filterBy method on this set one by one:

    (pseudocode of filterBy)
    Code:
    store.filterBy(function (rec) {
        var value = rec.get('FieldName').toLowerCase();
        return value.indexOf(query) !== -1;
    });
    1) filterBy("B") -> filtering data set searching of "B" entry in set's values (using String indexOf method)
    Result: "B", "ABC"

    2) filterBy("A")
    Result: "ABC" (But should be "A" and "ABC") because 1st call of the method added filter with filtering value "B"

    3) filterBy("") -> empty string
    result: the same as from the last call "ABC" (were applied filters from 1st ("B") and 2nd ("A") call)
    (But should be the full data set: "A", "B", "ABC")

    filterBy method works in the same way as addFilter method (comparing with 7th version of ExtJS), except ability to suppress event and pass only filtering function.


    Interesting thing is that the documentation was not changed at all!
    extjs 4.2.3
    extjs 7.0

  2. #2
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258
    Answers
    759

    Default

    The behaviour isn't going to get rolled back, it's been there for years now. To work around it:

    Code:
    store.addFilter({
        id: 'filterByWhatever',
        filterFn: r => true
    });
    store.addFilter({
        id: 'filterByWhatever',
        filterFn: r => false
    });
    console.log(store.filters.getCount())
    The filters collection will replace by id.

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2011
    Location
    Ukraine, Kyiv
    Posts
    28

    Default

    I know that this behavior is there for years and how to workaround is not a question, I know how to do it.
    My post mostly convey the information message (concern), taking in consideration that the code-base was changed and was tested many times, being there for these years and finally the method works completely in the contrast to its documentation.
    Documentation was simply copy/pasted, that's it.

    Similar thing is Ext.data.Store.filter() method without parameters, as these parameters are specified as optional in the documentation.
    Previously having several filters (already applied to the store) and changing for instance a value of one of the filters and triggering filter() method of a store leaded to apply/refresh the data set using existing filters:
    Code:
    filter.setValue('NewValueToFilterBy');
    store.filter();
    currently filter() method without parameters actually does nothing and should be used not convenient call on store data collection (if you don't want to replace changed filter)
    Code:
    filter.setValue('NewValueToFilterBy');
    store.getData().onFilterChange();

Tags for this Thread

Posting Permissions

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