Browse Source

Calculate column widths immediately if there is data (#20269)

Deferring the column width calculations, like done before,
causes flickering as each column is first rendered with its
minimum required width.

Change-Id: I02e6951a99dcb0cb9ad78a95915076d064fa9642
tags/7.7.1
Artur Signell 7 years ago
parent
commit
4d851ba21d

+ 3
- 1
client/src/main/java/com/vaadin/client/widgets/Grid.java View File

@@ -3177,7 +3177,9 @@ public class Grid<T> extends ResizeComposite implements
rescheduleCount = 0;
Scheduler.get().scheduleDeferred(this);
}
} else if (dataIsBeingFetched) {
} else if (currentDataAvailable.isEmpty()
&& dataIsBeingFetched) {
// No data available yet but something is incoming soon
Scheduler.get().scheduleDeferred(this);
} else {
calculate();

+ 85
- 0
uitest/src/main/java/com/vaadin/tests/components/grid/InitiallyDisabledGrid.java View File

@@ -0,0 +1,85 @@
package com.vaadin.tests.components.grid;

import java.util.ArrayList;
import java.util.Collection;

import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

public class InitiallyDisabledGrid extends UI {

public static class NotAPersonJustStringAndInt {
private String name;

public NotAPersonJustStringAndInt() {
}

public NotAPersonJustStringAndInt(String string, int i) {
name = string;
age = i;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

private int age;

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}
}

@Override
protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
setContent(layout);
layout.setSizeFull();
layout.setWidth("600px");
layout.setHeight("600px");
final Grid g = createGrid();
Button button = new Button("Sample button");

layout.addComponent(button);
VerticalLayout l = new VerticalLayout();
l.setSizeFull();
l.addComponent(g);

layout.addComponent(l);
layout.setExpandRatio(l, 1.0f);
}

private Grid createGrid() {
// Have some data
Collection<NotAPersonJustStringAndInt> people = new ArrayList<NotAPersonJustStringAndInt>();
for (int i = 0; i < 100; i++) {
people.add(new NotAPersonJustStringAndInt("A " + i, i));
}
// Have a container of some type to contain the data
BeanItemContainer<NotAPersonJustStringAndInt> container = new BeanItemContainer<NotAPersonJustStringAndInt>(
NotAPersonJustStringAndInt.class, people);

// Create a grid bound to the container
Grid grid = new Grid(container);
grid.setSizeFull();
grid.setColumnOrder("name", "age");

grid.setEnabled(false);

return grid;

}

}

+ 22
- 0
uitest/src/test/java/com/vaadin/tests/components/grid/InitiallyDisabledGridTest.java View File

@@ -0,0 +1,22 @@
package com.vaadin.tests.components.grid;

import org.junit.Assert;
import org.junit.Test;

import com.vaadin.testbench.elements.GridElement;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class InitiallyDisabledGridTest extends SingleBrowserTest {

@Test
public void columnsExpanded() {
openTestURL();

GridElement grid = $(GridElement.class).first();
GridCellElement col0 = grid.getCell(0, 0);
GridCellElement col1 = grid.getCell(0, 1);
Assert.assertTrue(col0.getSize().getWidth() > 250);
Assert.assertTrue(col1.getSize().getWidth() > 250);
}
}

Loading…
Cancel
Save