Grid Filtering

The following code is the filtering example fro V23.
What is the purpose of the label in the createFilterheader.
It does not seem necessary.
Grid grid = new Grid<>(Person.class, false);
Grid.Column nameColumn = grid.addColumn(createPersonRenderer())
Grid.Column emailColumn = grid.addColumn(Person::getEmail);
Grid.Column professionColumn = grid

List people = DataService.getPeople();
GridListDataView dataView = grid.setItems(people);
PersonFilter personFilter = new PersonFilter(dataView);

HeaderRow headerRow = grid.appendHeaderRow();

createFilterHeader(“Name”, personFilter::setFullName));
createFilterHeader(“Email”, personFilter::setEmail));
createFilterHeader(“Profession”, personFilter::setProfession));

private static Component createFilterHeader(String labelText,
Consumer filterChangeConsumer) {
Label label = new Label(labelText);
label.getStyle().set(“padding-top”, “var(–lumo-space-m)”)
.set(“font-size”, “var(–lumo-font-size-xs)”);
TextField textField = new TextField();
textField.getStyle().set(“max-width”, “100%”);
e → filterChangeConsumer.accept(e.getValue()));
VerticalLayout layout = new VerticalLayout(label, textField);

return layout;



It’s necessary for accessibility.

The label is not displayed anywhere. The column label is shown as normal. Can you expand a bit on the accessibility you refer to?

Sorry, it is actually added to the layout but in my case the column label seems to take precedence and is the only label that shows

Checking my code again, I have actually removed the label which is added to the layout. Will have to try again and check if the label is necessary in my case. Thx for reply, knoobie.

I’m not sure which example you are referring to but it’s highly possible that (if it’s not visible) it has the classname “sr-only” added so that’s only visible for Screenreader.

OK, the label is not necessary if the column headers are set.