Reputation: 311
I am trying to create a tree grid in vaadin. Is it possible to insert some data between two leafs of tree grid?
Upvotes: 1
Views: 314
Reputation: 1
I faced the similar problem, it seems the complex data structure to handle, it may create performance issues. I doubt whether it is possible in vaadin 8. Not possible to add new data in between the tree grid.
Upvotes: 0
Reputation: 1219
Not sure if there is an easier way, but you should be able to remove the last leaf(s), add your item, then re-add the removed leafs.
Example: assuming the following TreeGrid
TreeGrid<String> grid = new TreeGrid<>();
Column<String, String> col = grid.addColumn(String::toString);
grid.setHierarchyColumn(col);
TreeData<String> td = grid.getTreeData();
td.addItem(null, "root");
td.addItem("root", "first child");
td.addItem("root", "last child");
You can insert a middle child like so
td.removeItem("last child");
td.addItem("root", "middle child");
td.addItem("root", "last child");
grid.getDataProvider().refreshAll(); // Refresh for changes to TreeData to take effect
Upvotes: 1