diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java index c8c0fe9abd5..19520b337f9 100755 --- a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java @@ -1624,15 +1624,47 @@ protected > Class beanType, SerializableBiFunction updateQueueBuilder, B dataCommunicatorBuilder) { + this(beanType, updateQueueBuilder, dataCommunicatorBuilder, true); + } + + /** + * Creates a new grid with an initial set of columns for each of the bean's + * properties. The property-values of the bean will be converted to Strings. + * Full names of the properties will be used as the + * {@link Column#setKey(String) column keys} and the property captions will + * be used as the {@link Column#setHeader(String) column headers}. + *

+ * When autoCreateColumns is true, only the direct properties + * of the bean are included and they will be in alphabetical order. Use + * {@link Grid#setColumns(String...)} to define which properties to include + * and in which order. You can also add a column for an individual property + * with {@link #addColumn(String)}. Both of these methods support also + * sub-properties with dot-notation, eg. + * "property.nestedProperty". + * + * @param beanType + * the bean type to use, not null + * @param updateQueueBuilder + * the builder for new {@link UpdateQueue} instance + * @param dataCommunicatorBuilder + * Builder for {@link DataCommunicator} implementation this Grid + * uses to handle all data communication. + * @param + * the data communicator builder type + * @param + * the GridArrayUpdater type + * @param autoCreateColumns + * when true, columns are created automatically for + * the properties of the beanType + */ + protected > Grid( + Class beanType, + SerializableBiFunction updateQueueBuilder, + B dataCommunicatorBuilder, boolean autoCreateColumns) { this(50, updateQueueBuilder, dataCommunicatorBuilder); - Objects.requireNonNull(beanType, "Bean type can't be null"); Objects.requireNonNull(dataCommunicatorBuilder, "Data communicator builder can't be null"); - this.beanType = beanType; - propertySet = BeanPropertySet.get(beanType); - propertySet.getProperties() - .filter(property -> !property.isSubProperty()) - .forEach(this::addColumn); + configureBeanType(beanType, autoCreateColumns); } /** diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/treegrid/TreeGrid.java b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/treegrid/TreeGrid.java index e94ed75fad3..d6d51f6463e 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/treegrid/TreeGrid.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/treegrid/TreeGrid.java @@ -51,6 +51,7 @@ import com.vaadin.flow.data.provider.hierarchy.TreeData; import com.vaadin.flow.data.renderer.ComponentRenderer; import com.vaadin.flow.data.renderer.LitRenderer; +import com.vaadin.flow.data.renderer.Renderer; import com.vaadin.flow.dom.DisabledUpdateMode; import com.vaadin.flow.dom.Element; import com.vaadin.flow.function.SerializableBiFunction; @@ -268,7 +269,32 @@ private void addItemHasChildrenPathGenerator() { * the bean type to use, not {@code null} */ public TreeGrid(Class beanType) { - this(beanType, new TreeDataCommunicatorBuilder()); + this(beanType, true); + } + + /** + * Creates a new {@code TreeGrid} with an initial set of columns for each of + * the bean's properties. The property-values of the bean will be converted + * to Strings. Full names of the properties will be used as the + * {@link Column#setKey(String) column keys} and the property captions will + * be used as the {@link Column#setHeader(String) column headers}. + *

+ * When autoCreateColumns is true, only the direct properties + * of the bean are included, and they will be in alphabetical order. Use + * {@link #setColumns(String...)} to define which properties to include and + * in which order. You can also add a column for an individual property with + * {@link #addColumn(String)}. Both of these methods support also + * sub-properties with dot-notation, e.g. + * "property.nestedProperty". + * + * @param beanType + * the bean type to use, not null + * @param autoCreateColumns + * when true, columns are created automatically for + * the properties of the beanType + */ + public TreeGrid(Class beanType, boolean autoCreateColumns) { + this(beanType, new TreeDataCommunicatorBuilder<>(), autoCreateColumns); } /** @@ -286,7 +312,14 @@ public TreeGrid(Class beanType) { */ protected TreeGrid(Class beanType, DataCommunicatorBuilder dataCommunicatorBuilder) { - super(beanType, TreeGridUpdateQueue::new, dataCommunicatorBuilder); + this(beanType, dataCommunicatorBuilder, true); + } + + private TreeGrid(Class beanType, + DataCommunicatorBuilder dataCommunicatorBuilder, + boolean autoCreateColumns) { + super(beanType, TreeGridUpdateQueue::new, dataCommunicatorBuilder, + autoCreateColumns); setUniqueKeyProperty("key"); getArrayUpdater().getUpdateQueueData()