kikeee95
kikeee95

Reputation: 23

Vaadin14 Custom Grid Drag and Drop

I have a TreeGrid with a hierarchy and I want to add a Drag and Drop functionality to it.

My problem is, I only want two types of elements to be draggable, and they can only be dropped on into these two types and the root element.

So far I could manage to only allow these elements to be dragged, by returning the dragStartEvent when the element is a different type of element.

But how can I customize the allowed dropTargets when it is a Grid?

Right now the user can drop the element at any other grid element, and the only thing I can do is show an errormessage if the dropTarget is not the desired type, but this is not a good solution, they should see while dragging the item that its not droppable there.

Upvotes: 2

Views: 619

Answers (1)

Simon Martinelli
Simon Martinelli

Reputation: 36103

The grid has a Drag and a Drop Filter that you can use to decide if drag or drop.

void    setDragFilter(SerializablePredicate<T> dragFilter)
Sets the drag filter for this drag source.

void    setDropFilter(SerializablePredicate<T> dropFilter)
Sets the drop filter for this drag target.

Please checkout the documentation https://vaadin.com/components/vaadin-grid/java-examples/drag-and-drop

Upvotes: 2

Related Questions