vaadin-grid-exporter icon indicating copy to clipboard operation
vaadin-grid-exporter copied to clipboard

Export only selected items

Open nero404 opened this issue 1 year ago • 1 comments

Is there a option to export only selected items?

nero404 avatar May 10 '24 10:05 nero404

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()

AB-xdev avatar May 13 '24 08:05 AB-xdev

Question was answered

AB-xdev avatar Jun 27 '24 14:06 AB-xdev