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())
.setWidth(“230px”).setFlexGrow(0);
Grid.Column emailColumn = grid.addColumn(Person::getEmail);
Grid.Column professionColumn = grid
.addColumn(Person::getProfession);

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

grid.getHeaderRows().clear();
HeaderRow headerRow = grid.appendHeaderRow();

headerRow.getCell(nameColumn).setComponent(
createFilterHeader(“Name”, personFilter::setFullName));
headerRow.getCell(emailColumn).setComponent(
createFilterHeader(“Email”, personFilter::setEmail));
headerRow.getCell(professionColumn).setComponent(
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.setValueChangeMode(ValueChangeMode.EAGER);
textField.setClearButtonVisible(true);
textField.addThemeVariants(TextFieldVariant.LUMO_SMALL);
textField.setWidthFull();
textField.getStyle().set(“max-width”, “100%”);
textField.addValueChangeListener(
e → filterChangeConsumer.accept(e.getValue()));
VerticalLayout layout = new VerticalLayout(label, textField);
layout.getThemeList().clear();
layout.getThemeList().add(“spacing-xs”);

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.