I have one vaadin-flow grid having the second header row (added by using appendHeaderRow() method) for searching the content of the grid and TextField added for each column to that second header row.
Now, I am trying to find/get that TextField and it’s value which is searched/entered by user. But I can’t able to get that.
Please refers to attached screen-shot.
I need to find this highlighted TextField and ultimately the searched/entered value ‘2’
Basically, you create the component first to have a reference to it later on. Then you set it as the component of the header cell. There’s no need to “find” that TextField, since you already have the object reference.
You can use the TextField variable in the scope of the forEach loop, just like in the example. Take a closer look:
For each column:
Create a new TextField
Configure the TextField to apply filtering on the grid on value changes
Add the TextField to the header row
Of course you can create all of the TextFields in advance if you like. The point is just that you need to have a reference to the object to be able to configure it. It’s up to you where in the code you want to configure it.
Apparently the HeaderCell doesn’t have a getter for the component, so you need to do the mapping from column to text field yourself. So something like this:
Map<Column<?>, TextField> columnToFieldMap = new HashMap<Column<?>, TextField>();
grid.getColumns().forEach(column -> {
if (FirstColumn.equals(column) == false) {
TextField field = new TextField();
columnToFieldMap.put(column, field);
...
} else {
grid.getColumns().forEach(column -> {
// ***I need to get here TextField searched/entered value.***
columnToFieldMap.get(/* the column that has the text field you want to use */);
...