How to select data for a given user when using export CSV button

Hi,

I’am reaching out to inquire about the possibility to select data when exporting data table using a button with export CSV ?

In this screen below, i would like to export data only base on “type utilisateur”.
Thank you for your support,
Kind regards

I think you can create a query or relation with only the data you want and use that as the source for your CSV.

3 Likes

I’am sorry, i dont see how to proceed.

To further describe the context, users are able to attribute or remove medical device to participants in research context. I have a data table to track audit trail (each attribution or removal, with date). What i want is that a given user can extract the audit trail data, but limited to the research he participates in (“Type Utilisateur”), whichever was the user that attributed/removed devices, as long as it belongs to the same research team.

In the app, using filter, i can make user to see only audit trial for the study they participate, but when i create the button to extract csv, the whole data is extracted. If query or relation is adapted, please, could you further describe how you would proceed ?

Thank you very much for your kind support.
Regards,
Tristan

Hi @Tristan_Bonnevie

If I have well understood your use case, in your example:

  • Bonnevie Tristan should get all the records because you are belonging to “Etude faisabilité clinique” and also to “HYBREATH”
  • Test utilisateur should only retrieve rows 5 to 8 because he/she is only part of “Etude faisabilité clinique”

As Jeff suggested, a Query seems to be the best solution. To achieve that, we first need to list for each User what “Type utilisateur” he/she is part of.
To showcase this, I created a sample “Audit trail_test” table like this:

Now, let’s go for the hard work :stuck_out_tongue: . In the Users table:

  1. Create a Relation column (mine is named All Type utilisateur (relation)).
    You want to find all records of Audit trail_test > Utilisateurs that match the User > Name. Be sure to select “Match multiple” to find… multiple records. And don’t worry about the data displayed, it’s the value of the first column of the table. It just the way Glide tells you “I have found theses results!”.

  2. Create a Joined List column (All Type utilisateur (joined list)). You join texts in All Type utilisateur (relation) > Type utilisateur to get all the values of Type utilisateur available for this specific user row.

  3. Create a Query column (Records for Type utilisateur). This way, you can bring all the records where Type utilisateur is in the list of this user Type utilisateur. Same here, be sure the click on “Match multiple”.

In the layout, you now have two options:

  1. Keep using your Audit trail_test table and filter it out as you mentionned
  2. Use this Query as the source of your Collection (Data Grid in your screenshot). It’s probably more secure and efficient because if you change your Query to add more filters in the future, you’ll only have to apply the modification in the Query definition and it will be reflected in the view (but, you also might want to display something different of course)

And for your Export button, it’s the same logic:

  1. Add the button to the layout
  2. Select Generate CSV file
  3. Change Source data to User Profile > Records for Type utilisateur

At this point, if the User change, data also change based on the query. If I’m now connected:

BONUS: by clicking on “Select columns”, you’ll be able to select only the relevant columns you want in the export and also rename them (pretty cool feature I wanted to mention :smiley: )

In a nutshell: the Query column lets you retrieve data from another table and apply filters. This query can then be used as the source of a component or to aggregate data (such as counting the number of rows) :slight_smile:

Hope it helps!

2 Likes

Dear @Nicolas_Joseph, your detailed answer has not only been helpfull, it totally resolved my issue.

I am very gratefull for your help. Glide community is amazing :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.