A few things to consider in this discussion:
Firstly - why is "useAdvancedCriteria" required when you override 'getCriterion' to ensure that method fires?
As you know, DynamicForm.getValuesAsCriteria() [which is ultimately used by the filterEditor to produce criteria] can return simple or advanced criteria, depending on the items within the form and how they are configured.
Individual formItems indicate that they will return advanced criteria [requiring the form as a whole to return advancedCriteria] if formItem.hasAdvancedCriteria() returns true. If any item returns advanced criteria, each item will return advanced criteria, produced by evaluating item.getCriterion(), rather than just putting their current value into a simple criterion object.
By setting 'listGrid.useAdvancedCriteria' to true you're forcing the filter form to always produce advanced criteria by calling the getCriterion() method, which causes your override to be called. This is a valid approach, or you could set useAdvancedCriteria directly on the item, which would cause hasAdvancedCriteria() to always return true for the item.
Secondly - why does the text field value get cleared out when the criterion with a null value is applied to the field?
When the system performs a filter in a grid, a round-trip occurs where each item generates a criterion and applies it to the grid, and then the form is effectively refreshed to display the criteria currently applied to the grid. In this case a text value like "Ot" is converted into a null field value, and then when the text item is refreshed to display the new criteria, the original text value is cleared out.
Ultimately it might be possible to get this working with the approach you've started to take by
- overriding getCriterion() as you have
- setting the useAdvancedCriteria flag to true on the item
- overriding formItem.setCriterion() to effectively be a no-op if the criterion value for the field is null
But taking this approach would mean that if your application code called 'listGrid.filterData()' passing in empty criteria it would fail to clear the field value - the item would be unable to distinguish between the null that came from the user typing a too-short string and this case where the criterion was explicitly being cleared.
A better approach is probably to leverage filterEditorSubmit(), getFilterEditorCriteria() and setFilterEditorCriteria() to map from the criteria produced by the editor to the ones you actually want to apply to the data.
Something like this should probably work:
Code:
filterEditorSubmit : function () { var criteria = this.getFilterEditorCriteria(); var modifiedCriteria = {...criteria}; if (criteria.capital != null && criteria.capital.length < 3) { modifiedCriteria.capital = null; } // filter data without the stripped fields this.filterData(modifiedCriteria); // re-display the original criteria in the filter editor this.setFilterEditorCriteria(criteria); // suppress default behavior return false; }, ...
Regards
Isomorphic Software
Leave a comment: