com.vaadin.flow.component.treegrid.

Class TreeGrid<T>

    • Constructor Detail

      • TreeGrid

        public TreeGrid()

        Creates a new TreeGrid without support for creating columns based on property names. Use an alternative constructor, such as TreeGrid(Class), to create a TreeGrid that automatically sets up columns based on the type of presented data.

      • TreeGrid

        public TreeGrid(Class<T> beanType)

        Creates a new 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 column keys and the property captions will be used as the column headers.

        Parameters:

        beanType - the bean type to use, not null

      • TreeGrid

        public TreeGrid(HierarchicalDataProvider<T,?> dataProvider)

        Creates a new TreeGrid using the given HierarchicalDataProvider, without support for creating columns based on property names. Use an alternative constructor, such as TreeGrid(Class), to create a TreeGrid that automatically sets up columns based on the type of presented data.

        Parameters:

        dataProvider - the data provider, not null

    • Method Detail

      • setUniqueKeyDataGenerator

        public void setUniqueKeyDataGenerator(String propertyName,
                                              ValueProvider<T,String> uniqueKeyProvider)

        Sets property name and value provider for unique key in row's generated JSON.

        Default property name is 'key' and value is generated by bean's hashCode method.

        Parameters:

        propertyName - Property name in JSON data

        uniqueKeyProvider - Value provider for the target property in JSON data

      • setDataProvider

        public void setDataProvider(DataProvider<T,?> dataProvider)

        Description copied from interface: HasDataProvider

        Sets the data provider for this listing. The data provider is queried for displayed items as needed.

        Specified by:

        setDataProvider in interface HasDataProvider<T>

        Overrides:

        setDataProvider in class Grid<T>

        Parameters:

        dataProvider - the data provider, not null

      • addHierarchyColumn

        public Grid.Column<T> addHierarchyColumn(ValueProvider<T,?> valueProvider)

        Adds a new Hierarchy column to this Grid with a value provider. The value is converted to String when sent to the client by using String.valueOf(Object).

        Hierarchy column is rendered by using 'vaadin-grid-tree-toggle' web component.

        Parameters:

        valueProvider - the value provider

        Returns:

        the created hierarchy column

      • setHierarchyColumn

        public Grid.Column<T> setHierarchyColumn(String propertyName)

        Note: This method can only be used for a TreeGrid created from a bean type with TreeGrid(Class).

        Resets columns and their order based on bean properties.

        This is a shortcut for removing all columns and then calling Grid.addColumn(String) for each property except hierarchy column in the bean and addHierarchyColumn(String) for the given propertyName.

        Previous column order is preserved.

        You can add columns for nested properties with dot notation, eg. "property.nestedProperty"

        Note that this also resets the headers and footers.

        Parameters:

        propertyName - a target hierarchy column property name

        Returns:

        the created hierarchy column

      • setHierarchyColumn

        public Grid.Column<T> setHierarchyColumn(String propertyName,
                                                 ValueProvider<T,?> valueProvider)

        Note: This method can only be used for a TreeGrid created from a bean type with TreeGrid(Class).

        Resets columns and their order based on bean properties.

        This is a shortcut for removing all columns and then calling Grid.addColumn(String) for each property except hierarchy column in the bean and addHierarchyColumn(String) or addHierarchyColumn(ValueProvider) for the given propertyName.

        Previous column order is preserved.

        You can add columns for nested properties with dot notation, eg. "property.nestedProperty"

        Note that this also resets the headers and footers.

        Parameters:

        propertyName - a target hierarchy column property name

        valueProvider - optional value provider

        Returns:

        the created hierarchy column

      • setColumns

        public Grid.Column<T> setColumns(String hierarchyPropertyName,
                                         ValueProvider<T,?> valueProvider,
                                         Collection<String> propertyNames)

        Note: This method can only be used for a TreeGrid created from a bean type with TreeGrid(Class).

        Sets the columns and their order based on the given properties.

        This is a shortcut for removing all columns and then calling Grid.addColumn(String) for each property except hierarchy property in the bean and addHierarchyColumn(String) for the given hierarchyPropertyName.

        You can add columns for nested properties with dot notation, eg. "property.nestedProperty"

        Note that this also resets the headers and footers.

        Parameters:

        hierarchyPropertyName - a target hierarchy column property name

        valueProvider - optional value provider

        propertyNames - set of properties to create columns for. Including given hierarchyPropertyName

        Returns:

        the hierarchy column

      • expand

        public void expand(T... items)

        Expands the given items.

        If an item is currently expanded, does nothing. If an item does not have any children, does nothing.

        Parameters:

        items - the items to expand

      • expand

        public void expand(Collection<T> items)

        Expands the given items.

        If an item is currently expanded, does nothing. If an item does not have any children, does nothing.

        Parameters:

        items - the items to expand

      • expand

        protected void expand(Collection<T> items,
                              boolean userOriginated)

        Expands the given items.

        Parameters:

        items - the items to expand

        userOriginated - true if a ExpandEvent triggered by this operation is user originated, false otherwise.

      • expandRecursively

        public void expandRecursively(Stream<T> items,
                                      int depth)

        Expands the given items and their children recursively until the given depth.

        depth describes the maximum distance between a given item and its descendant, meaning that expandRecursively(items, 0) expands only the given items while expandRecursively(items, 2) expands the given items as well as their children and grandchildren.

        This method will not fire events for expanded nodes.

        Parameters:

        items - the items to expand recursively

        depth - the maximum depth of recursion

        Since:

        8.4

      • expandRecursively

        public void expandRecursively(Collection<T> items,
                                      int depth)

        Expands the given items and their children recursively until the given depth.

        depth describes the maximum distance between a given item and its descendant, meaning that expandRecursively(items, 0) expands only the given items while expandRecursively(items, 2) expands the given items as well as their children and grandchildren.

        This method will not fire events for expanded nodes.

        Parameters:

        items - the items to expand recursively

        depth - the maximum depth of recursion

        Since:

        8.4

      • collapse

        public void collapse(T... items)

        Collapse the given items.

        For items that are already collapsed, does nothing.

        Parameters:

        items - the collection of items to collapse

      • collapse

        public void collapse(Collection<T> items)

        Collapse the given items.

        For items that are already collapsed, does nothing.

        Parameters:

        items - the collection of items to collapse

      • collapse

        protected void collapse(Collection<T> items,
                                boolean userOriginated)

        Collapse the given items.

        Parameters:

        items - the collection of items to collapse

        userOriginated - true if a CollapseEvent triggered by this operation is user originated, false otherwise.

      • collapseRecursively

        public void collapseRecursively(Stream<T> items,
                                        int depth)

        Collapse the given items and their children recursively until the given depth.

        depth describes the maximum distance between a given item and its descendant, meaning that collapseRecursively(items, 0) collapses only the given items while collapseRecursively(items, 2) collapses the given items as well as their children and grandchildren.

        This method will not fire events for collapsed nodes.

        Parameters:

        items - the items to collapse recursively

        depth - the maximum depth of recursion

        Since:

        8.4

      • collapseRecursively

        public void collapseRecursively(Collection<T> items,
                                        int depth)

        Collapse the given items and their children recursively until the given depth.

        depth describes the maximum distance between a given item and its descendant, meaning that collapseRecursively(items, 0) collapses only the given items while collapseRecursively(items, 2) collapses the given items as well as their children and grandchildren.

        This method will not fire events for collapsed nodes.

        Parameters:

        items - the items to collapse recursively

        depth - the maximum depth of recursion

        Since:

        8.4

      • getItemsWithChildrenRecursively

        protected Collection<T> getItemsWithChildrenRecursively(Collection<T> items,
                                                                int depth)

        Gets given items and their children recursively until the given depth.

        depth describes the maximum distance between a given item and its descendant, meaning that getItemsWithChildrenRecursively(items, 0) gets only the given items while getItemsWithChildrenRecursively(items, 2) gets the given items as well as their children and grandchildren.

        Parameters:

        items - the items to expand recursively

        depth - the maximum depth of recursion

        Returns:

        collection of given items and their children recursively until the given depth

      • isExpanded

        public boolean isExpanded(T item)

        Returns whether a given item is expanded or collapsed.

        Parameters:

        item - the item to check

        Returns:

        true if the item is expanded, false if collapsed