0

How can I create a filter on multiple fields, which filters on the server, and not in the local store?

So far I've only gotten locally.

onFilter: function(field, newValue, oldValue, options){
    var grid = Ext.getCmp('grid');
    grid.store.clearFilter();

    if (newValue) {
        var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i");
        grid.store.filter({
            filterFn: function(record) {
                return matcher.test(record.get('id')) ||
                    matcher.test(record.get('names'));
            }
        });
    }
}

1 Answer 1

1

You cannot set filters with filterFn on remote filtering. Remote filtering can only take property-value-operator combinations that are sent to the backend, and have to be evaluated and acted on by the backend.

To filter on multiple properties, you can of course send multiple filters to the backend:

store.addFilters([{
    id: 'idFilter',
    property: 'id',
    operator: 'eq',
    value: newValue
},{
    id: 'nameFilter',
    property: 'names',
    operator: 'like',
    value: newValue
}]);

The backend then has to evaluate and apply these filters to the data. The values are sent to the backend without client-side validation or usage, so you could even send arbitrary property or operator names to the backend:

store.addFilters([{
    id: 'idOrNameFilter',
    property: 'idOrName',
    operator: 'somethingsomething',
    value: newValue
}]);

You would just have to tell your backend to parse the property name correctly from the parameter string and act accordingly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.