@@ -576,12 +576,12 @@ the height of all rows in the Grid. | |||
Use [classname]#Button# in [classname]#Grid#: | |||
+ | |||
---- | |||
grid.addColumn(person -> { | |||
grid.addComponentColumn(person -> { | |||
Button button = new Button("Click me!"); | |||
button.addClickListener(click -> | |||
Notification.show("Clicked: " + person.toString())); | |||
return button; | |||
}, new ComponentRenderer()); | |||
}); | |||
// make sure the buttons fit in the cells of the Grid | |||
grid.setRowHeight(40); | |||
---- |
@@ -2420,6 +2420,25 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, | |||
return column; | |||
} | |||
/** | |||
* Adds a column that shows components. | |||
* <p> | |||
* This is a shorthand for {@link #addColum()} with a | |||
* {@link ComponentRenderer}. | |||
* | |||
* @param componentProvider | |||
* a value provider that will return a component for the given | |||
* item | |||
* @return the new column | |||
* @param <V> | |||
* the column value type, extends component | |||
* @since 8.1 | |||
*/ | |||
public <V extends Component> Column<T, V> addComponentColumn( | |||
ValueProvider<T, V> componentProvider) { | |||
return addColumn(componentProvider, new ComponentRenderer()); | |||
} | |||
/** | |||
* Creates a column instance from a value provider and a renderer. | |||
* | |||
@@ -2428,6 +2447,8 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents, | |||
* @param renderer | |||
* the renderer | |||
* @return a new column instance | |||
* @param <V> | |||
* the column value type | |||
* | |||
* @since 8.0.3 | |||
*/ |
@@ -15,7 +15,6 @@ import com.vaadin.tests.util.AlwaysLockedVaadinSession; | |||
import com.vaadin.tests.util.MockUI; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.renderers.ComponentRenderer; | |||
/** | |||
* Test to validate clean detaching in Grid with ComponentRenderer. | |||
@@ -37,11 +36,11 @@ public class GridComponentRendererTest { | |||
dataProvider = DataProvider.ofCollection(backend); | |||
grid = new Grid<>(); | |||
grid.setDataProvider(dataProvider); | |||
grid.addColumn(p -> { | |||
grid.addComponentColumn(p -> { | |||
oldComponent = testComponent; | |||
testComponent = new Label(); | |||
return testComponent; | |||
}, new ComponentRenderer()); | |||
}); | |||
new MockUI() { | |||
@Override | |||
public Future<Void> access(Runnable runnable) { |
@@ -24,9 +24,9 @@ public class GridComponents extends AbstractTestUIWithLog { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Grid<String> grid = new Grid<String>(); | |||
Grid<String> grid = new Grid<>(); | |||
grid.addColumn(string -> new Label(string), new ComponentRenderer()); | |||
grid.addColumn(string -> { | |||
grid.addComponentColumn(string -> { | |||
if (textFields.containsKey(string)) { | |||
log("Reusing old text field for: " + string); | |||
return textFields.get(string); | |||
@@ -41,7 +41,7 @@ public class GridComponents extends AbstractTestUIWithLog { | |||
textFields.put(string, textField); | |||
}); | |||
return textField; | |||
}, new ComponentRenderer()); | |||
}); | |||
grid.addColumn(string -> { | |||
Button button = new Button("Click Me!", | |||
e -> Notification.show( |