0

I'm working on a project that exports vaadin grid data to excel. To get the data from the grid cells, the column.getRenderer().getValueProviders() method is used, similar to how it's done in this addon. Renderer.getValueProviders() was deprecated in vaadin 23.1 and does not exist in vaadin 24.

Is there a way to get the values from a cell in vaadin 24?

1 Answers1

0

I don't see a "direct" method to do that.

You would need to use reflection:

protected <X> ValueProvider<T, X> getValueProvider(final Grid.Column<T> column)
{
    final Renderer<T> r = column.getRenderer();
    if(r instanceof BasicRenderer)
    {
        try
        {
            final Method getValueProvider = BasicRenderer.class.getDeclaredMethod("getValueProvider");
            getValueProvider.setAccessible(true);
            return (ValueProvider<T, X>)getValueProvider.invoke(r);
        }
        catch(final IllegalAccessException | IllegalArgumentException | InvocationTargetException
                    | NoSuchMethodException | SecurityException e)
        {
            // Something went wrong, but it's not our place to say what or why.
        }
    }
    return null;
}

See:

https://github.com/xdev-software/vaadin-grid-exporter/blob/develop/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/grid/GridDataExtractor.java and https://github.com/FlowingCode/GridExporterAddon/blob/master/src/main/java/com/flowingcode/vaadin/addons/gridexporter/GridExporter.java

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82