Class ListSorter<T>

  • Type Parameters:
    T - Grid row data type

    public class ListSorter<T>
    extends Object
    Provides sorting facility from Grid for the ListDataSource in-memory data source.
    Since:
    7.4
    Author:
    Vaadin Ltd
    • Constructor Detail

      • ListSorter

        public ListSorter​(Grid<T> grid)
        Constructs a sorting facility for the given Grid.
        Parameters:
        grid - the Grid that needs sort handling
    • Method Detail

      • removeFromGrid

        public void removeFromGrid()
        Detach this Sorter from the Grid. This unregisters the sort event handler which was used to apply sorting to the ListDataSource.
      • setComparator

        public <C> void setComparator​(Grid.Column<C,​T> column,
                                      Comparator<C> comparator)
        Assign or remove a comparator for a column. This comparator method, if defined, is always used in favour of 'natural' comparison of objects (i.e. the compareTo of objects implementing the Comparable interface, which includes all standard data classes like String, Number derivatives and Dates). Any existing comparator can be removed by passing in a non-null GridColumn and a null Comparator.
        Type Parameters:
        C - the column data type
        Parameters:
        column - a grid column. May not be null.
        comparator - comparator method for the values returned by the grid column. If null, any existing comparator is removed.
      • getComparator

        public <C> Comparator<C> getComparator​(Grid.Column<C,​T> column)
        Retrieve the comparator assigned for a specific grid column.
        Type Parameters:
        C - the column data type
        Parameters:
        column - a grid column. May not be null.
        Returns:
        a comparator, or null if no comparator for the specified grid column has been set.
      • clearComparators

        public void clearComparators()
        Remove all comparator mappings. Useful if the data source has changed but this Sorter is being re-used.