the right way to update grid

Grid grid = new Grid();
BeanItemContainer container = new BeanItemContainer<>(Type.class);
GeneratedPropertyContainer containerMain;

container.addAll(list);
containerMain = new GeneratedPropertyContainer(container);

grid.setContainerDataSource(containerMain);

how to update grid with saving states like scroll position and selection?