DataProvider for search implementation with TextField and Grid

Hi, I’ve tried to find the correct way to implement to implement a DataProvider when the Grid should stay empty up until some text has been entered into an TextField. The Examples that I have seen filter just the allready present data. Currently I’m just setting the items ofa grid for every change in the TextField, but that solution doesn’t seem quite right to me.

Thanks for the help.

Kind Regards

If I understand correctly, you want to have your TextField act as a “normal” Filter field, but the grid may only be filled once the user has changed the value of the textField once?
What if the user writes something, then clears the value again? should the grid become empty again?

In order to delay the setting of the items in the grid until the user has given input, you could do something like this which will call grid.setItems(..) the first time a valueChangeEvent of the textfield is fired:

private boolean userInputWasGiven = false;
...

TextField userInput = new TextField();
userInput.setValueChangeMode(...); // choose the ValueChangeMode that suits your needs here.
userInput.addValueChangeListener(event -> {
	if(!userInputWasGiven){
		grid.setItems(allItems);
		userInputWasGiven = true;
	}
	// TODO: filtering. see https://stackoverflow.com/questions/60256269/simple-example-of-filtering-items-in-a-grid-in-vaadin-flow-14/60259207#60259207
});