xdev-software / vaadin-grid-exporter

Makes it possible to export Vaadin Grids to different formats

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Export only selected items

nero404 opened this issue · comments

Is there a option to export only selected items?

Yes this is possible, but it's currently not built into the default library.

You can however achieve that by writing a custom GridDataExtractor and supplying it to GridExporter using withGridDataExtractorSupplier.

Example:

public class OnlySelectItemsGridDataExtractor<T> extends GridDataExtractor<T>
{
	public OnlySelectItemsGridDataExtractor(final Grid<T> grid)
	{
		super(grid);
	}
	
	@Override
	protected Stream<T> getSortedAndFilteredData(final Grid<T> grid)
	{
		final Set<T> selectedItems = grid.getSelectedItems();
		return super.getSortedAndFilteredData(grid)
			.filter(selectedItems::contains);
	}
}

Example usage:

GridExporter.newWithDefaults(this.grExamples)
	.withGridDataExtractorSupplier(OnlySelectItemsGridDataExtractor::new)
	.open()

Question was answered