vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
868 stars 58 forks source link

The filter of a Grid/AutoGrid should be accessible from outside the Grid/AutoGrid #2350

Open alxflam opened 2 months ago

alxflam commented 2 months ago

Describe your motivation

It's a common use case for many applications to allow users to export/download data of grids (e.g. as CSV, XLSX). This can be done in Hilla by making use of a plain Spring RestController which provides the export/download endpoint and dynamically creates the file. Now the problem is: The backend endpoint needs to know exactly which data should be included in the resulting file, and thus the current filter state of the grid needs to be passed to the download endpoint.

Describe the solution you'd like

Maybe this could be done similar to #1769 which created an accessible refresh trigger.

Create a react ref for the grid: const ref = useRef<AutoGridRef>(null); Then use this ref to collect the filter in the client download event handler to get the filter and pass it to the actual download/export endpoint: const filter = ref.current?.filter();

The filter only needs to be read. Changing the filter programmatically is not required for the mentioned use case.

Describe alternatives you've considered

Additional context

Origin: https://vaadin.com/forum/t/hilla-endpoint-with-custom-headers-e-g-for-file-download/165993/2

sagarbendale commented 3 weeks ago

I would like to mention, that it is very common to retain the filter and apply it before the list is initialized. eg. user navigates away from the list page and then comes back. Along with read capability writing to the filter is also much needed.