Export filtered table via getDisplayedData / Button

Hello everyone,
I would like to introduce myself briefly. I work as a volunteer in an animal breeders' association (I am not paid) and provide support on all IT topics (website, membership fees and also look after the membership database).
The latter was originally maintained via Excel. I replaced it with MS Access a few years ago. I would now like to replace Access for many reasons. A few years ago, I discovered a potential solution with retool, which I would now like to implement in the medium term. I sincerely hope that I can manage this even as a non-programmer. However, I am willing to learn... :slight_smile:

Now to my first problem: I want to export the data of a filtered table. As I have read, this can be done via a JavaScript getDisplayData()
see here: Download csv files on filtered table - #6 by Tess

What do I have to enter as an action in the click handler so that I can export the data?

Thank you in advance!

Hi @Azathoth,

It looks like you're on the right path. If you want the data from the table, you need to adjust the code in your get_displayed_Stammdaten function a little bit. Change it to:

return await table_Stammdaten.getDisplayedData()

Then, the in that "data" input, enter {{ get_displayed_Stammdaten.data }}, which will be the result of your JS query.

1 Like

@MikeCB Thank you for your solution. If I run the script manually before I start the export, it works great!

But... if I include the whole thing in the button via the event handler, I always have to click on Export twice (!) before I get the updated filtered data.

To understand:
I filter the data e.g. Name: Max Mustermann, click on Export... no (!) file is created.
I filter again: example Julia Meyer and export: I get Max Mustermann... the next click contains Julia.

I assume that the event handlers are processed in parallel and not one after the other. I had already tried to set a debounce in the hope that this would help... But it doesn't seem to help.

Do you have another idea?

Hi @Azathoth,

Apologies, I didn't review the export results in enough detail. Here is a better (and working) way of doing it.

Change your button event handler to look like this, it tells the button to execute the JS query:
image

Then, in your get_displayed_Stammdaten query, go to the Success part of the event handlers section, and add an export event handler.
image

So the flow is now Click Button -> Run Query -> On Success, Export