Select rows through a csv file

So I currently have a table in retool with primary key ID that has row selection set to multiple. One of the things I want to do is keep the multiple row selection enabled but I want to allow a user to upload a csv file with a ID column and the table will parse the IDs from the csv file and select the rows that have the corresponding IDs.

Ex
retool table
ID other columns with information
1
2
3
4
5
6

csv
ID
2
4
6

output: after uploading csv file the table will select the records with ID 2,4,6.
After the csv file selects the IDs that were present, a user can continue selecting records if needed.

the csv file I am testing with will have ID as the first column but I need help figuring out how to implement the row selection through the csv file.

This is definitely doable.

Use one of the file components to upload the file, convert the base64 to string, parse the csv to json, gather the ids into a list, and use table1.selectRow(). You will also need to set the primary key property on the table component to your ID field.

table1.selectRow({mode: 'key', key: idList});

I am very new to retool and more of a visual learner. I will try to implement your solution but if you can simulate that it on a dummy table of your own that will be very helpful for me.

Something like this?

Add a fileButton component to the canvas, enable "Parse files".
Screenshot 2023-10-19 at 12.02.03 PM

Make sure your table has your ID field set as the "Primary key"
Screenshot 2023-10-19 at 12.04.12 PM

Create a js query with something like

const importedData = fileButton1.parsedValue[0];
const idList = importedData.map(row => row.id) 

console.log(idList);

table1.selectRow({mode: 'key', key: idList});
//...

Configure an event handler on you fileButton where the parse event triggers your js query.
Screenshot 2023-10-19 at 12.08.34 PM

1 Like

Yea it worked perfectly, thank you for the assistance.

@matth So when I ran your js it does work only when the file type is a csv file. So I tried parsing an excel file and I was receiving errors. I took the IDs from the excel file and placed them in the csv file and it was able to do the selects accordingly. I think there is an issue when trying to parse an excel file.

It looks like parsedValue is slightly different when excel is parsed; there's support for sheets. You'll have to handle that in your js query if you want to support both excel and csv
Screenshot 2023-10-23 at 10.16.26 AM

The screenshot above is from the State explorer.