Checklist
What is/are your question(s)?
Hello everyone.
I want to provide a column-specific filter component (ComboBox) that automatically lists all distinct values contained in that particular column. The component is created inside a custom TypeValueComponentProvider, but the method getNewComponentData(Class<?> clazz) does not seem to expose any information about the column for which the filter component is created.
Problem:
Inside getNewComponentData(...), I need to access the column key (or another column identifier) in order to load the column’s distinct values from a service:
public class StringSingleValueComponentProvider extends DefaultTypeValueComponentProvider<SingleValue<String>> {
public StringSingleValueComponentProvider() {
super(Set.of(String.class));
}
@Override
public Class<?> valueContainerClass() {
return SingleValue.class;
}
@Override
public SingleValue<String> createEmptyValueContainer() {
return new SingleValue<>();
}
@Override
public TypeValueComponentData<SingleValue<String>> getNewComponentData(final Class<?> clazz) {
ComboBox<String> comboBox = new ComboBox<>();
// Desired: get column key here
// String columnKey = ...;
// comboBox.setItems(ValueService.getDistinctValues(columnKey));
Binder<SingleValue<String>> binder = new Binder<>();
this.bindBinderTypeSafe(binder, comboBox, SingleValue::getValue, SingleValue::setValueUnchecked);
return new TypeValueComponentData<>(binder, comboBox);
}
protected <B, F> void bindBinderTypeSafe(Binder<B> binder,
HasValue<?, F> field,
ValueProvider<B, F> getter,
Setter<B, F> setter) {
binder.forField(field)
.asRequired()
.bind(getter, setter);
}
@Override
public String serialize(final TypeValueComponentData<SingleValue<String>> typeValueComponentData) {
return typeValueComponentData.binder().getBean().getValue();
}
@Override
public void deserializeAndApply(
String input,
TypeValueComponentData<SingleValue<String>> typeValueComponentData){
if (typeValueComponentData.component() instanceof ComboBox<?> comboBox) {
comboBox.getListDataView().getItems()
.filter(String.class::isInstance)
.map(String.class::cast)
.filter(value -> Objects.equals(value, input))
.findFirst()
.ifPresent(v -> {
Binder<SingleValue<String>> binder = typeValueComponentData.binder();
binder.getBean().setValueUnchecked(v);
binder.refreshFields();
});
}
}
}
However, I could not find any API method or parameter that provides context about the Grid column that triggers the creation of the filter component.
- Is there currently any supported way to determine the column (or column key) from inside getNewComponentData() or any other part of the component provider?
- If not, would it be possible to extend the API so that the component provider receives the column context (e.g., the column key), enabling the creation of column-specific filter components?
Thank you in advance for any guidance or clarification.
Checklist
What is/are your question(s)?
Hello everyone.
I want to provide a column-specific filter component (ComboBox) that automatically lists all distinct values contained in that particular column. The component is created inside a custom TypeValueComponentProvider, but the method getNewComponentData(Class<?> clazz) does not seem to expose any information about the column for which the filter component is created.
Problem:
Inside getNewComponentData(...), I need to access the column key (or another column identifier) in order to load the column’s distinct values from a service:
However, I could not find any API method or parameter that provides context about the Grid column that triggers the creation of the filter component.
Thank you in advance for any guidance or clarification.