flow-components
flow-components copied to clipboard
API for adding filter components to custom columns.
There is no public API for adding a filter component into a custom column (similar to what is provided when using reflection). Thus, if I need to do some fine-tuning (such as formatting the column by using a Renderer) I need to provide my own implementation of CrudGrid::setupFiltering because there is no way to call or override that method.
This could be fairly simple, I think something like this added to CrudGrid
:
public InputField createFilterField(Column column) {
return new TextField();
}
Then, in setupFiltering
just check if the returned Component implements HasValueChangeMode
before setting it to EAGER, and HasPlaceholder
before setting it.
That way, we could extend CrudGrid, and create whatever field we want for filtering - a checkbox for booleans, Select for Enums, add validation for numbers, etc.
Oh, and returning null
could indicate no filtering for that column.
I just realized this may not be the right issue for my comments, sorry. This was specific to custom/generated columns, not the general/default filter case, which is what I was thinking about. let me know if I should file this separately.
Exploring further, why not store HeaderRow filterRow
as a field, and initialize on first call to a new method:
public InputField addDefaultFilter(Column<E> column);
Which is the body of the forEach()
in the current SetupFiltering()
, modified as suggested above to allow custom filter implementations.
HeaderRow already maps cells by Column<E>, so multiple calls would just replace the filter field.
I think this would allow filtering on calculated columns as well as default ones, and play nice with the enableDefaultFilters
functionality as it currently exists, with the added flexibility of adding columns dynamically, calculated or not, with custom implementations of filtering based on business rules and data types, without much code required to enable it in the framework or use it in practice.
Just mentioning that the current code of CrudGrid
in flow-components has no significative changes w.r.t vaadin-crud-flow 2.0.1 upon which this ticket had been reported.