Clear grid

Hello,

I have the following problem when clearing a grid.

After clicking a button, the grid should be cleared and rerendered. But when I do

for(Column column: grid.getColumns()) {
        	grid.removeColumn(column);
}


//... some code to add new columns and setItems..
grid.addColumn(...)
grid.setItems(...)

//And then sorting the grid via
for (Column<Row> column : grid.getColumns()) {
		column.setSortable(true);
}

Then, the following error-message appears in the browser:
TypeError: Cannot read property ‘parentNode’ of null.

What is going on here?

Instead of clearing the Grid, why not create a new one?

Thanks Olli, this is a good workaround.

Hmm, maybe you can help me again.

I Have a vertial Layout in which i have 3 horizontal Layouts each with a grid.
If I added the first horizontal Layout, everything is fine. But when I add a grid to the second Horizontal Layout, display it, there are scrollbars showing up. The vertical Scrollbar is ok, but how i can avoid the horizontal scrollbar?

I guess you’ll need to control the widths of the component so they won’t take as much horizontal space.

I set the 3-sub views width by

this.view1.setWidth("90%");
this.view2.setWidth("90%");
this.view3.setWidth("90%"); 

but this doesn’t fix my problem.

I fixed the problem by using the annotation @BodySize(). :slight_smile: The problem was the width 100vw in the body element.

Nice! Maybe this thread will help other people who encounter the same issue.