Sencha Grid同一属性添加多Not Filter无效问题求助
Hey there! I totally get why this is frustrating—adding multiple <> filters for the same property should logically exclude all those values, but instead only the last one takes effect. Let's break down why this happens and how to fix it.
Why Your Original Code Isn't Working
Most data store frameworks (like Ext JS, which your syntax appears to use) treat multiple filters targeting the same property as overrides rather than cumulative rules. When you add three separate filters for invitationStatus, the store ends up replacing each previous filter with the next one, leaving only the last active.
Solution 1: Use a Custom Filter Function (Most Flexible)
Instead of multiple individual filters, create a single filter that checks if the record's value isn't in your excluded list using a custom function. This works for both local and remote filtering (if your backend supports custom logic, or you're filtering client-side):
store.addFilter({ filterFn: function(record) { // List all statuses you want to exclude const excludedStatuses = ['IN_PROGRESS', 'SENT_BY_COMPANY', 'SENT_BY_SYSTEM']; // Return true only if the status is NOT in the excluded list return !excludedStatuses.includes(record.get('invitationStatus')); } });
Solution 2: Use the "notin" Operator (Framework-Dependent)
If your store framework supports the notin operator (Ext JS does, for example), you can simplify this into a single filter that targets all excluded values at once:
store.addFilter({ property: 'invitationStatus', operator: 'notin', value: ['IN_PROGRESS', 'SENT_BY_COMPANY', 'SENT_BY_SYSTEM'] });
Just note: If you're using remote filtering (where the server handles the filter logic), your backend needs to support the notin operator for this to work correctly.
Quick Tip
Double-check your store's remoteFilter setting:
- If
remoteFilter: true, make sure your backend can process the filter format you choose (either the custom function's logic or thenotinoperator). - If
remoteFilter: false, both solutions above will work seamlessly on the client side.
内容的提问来源于stack exchange,提问作者user2915010

