Hi,
When we import data, eg excel file/CSV, into the Glide table, we can do so using the import from the data …
If we want to build a function for users to import by clicking a button on the front end of the app (instead of messing with tables from backend), how could we do it?
It’s possible, but requires some advanced techniques involving Helper Tables, JavaScript and the Glide API. I made a proof of concept App that does it earlier this year, at the prompting of Bob Petitto.
The original concept used Make to insert the rows, but that was before we had the Call API action. So that would be an option now.
If the above video won’t play, paste the below link into a browser window.
I can’t share the App, but I can describe the approach.
Create a Helper Table and add enough rows to cater for the largest CSV file you are expecting. eg. if you want to add a CSV file with 200 lines, then you’ll need a 200 row Helper Table
Number the Helper Table rows, beginning at zero
Capture the uploaded CSV file in a User Specific Column
Use a Single Value column to apply the User Specific Column value to all rows in the Helper Table
Use a JavaScript column to fetch the CSV file, parse it, and output a JSON string representing the column values required for each add-row-to-table mutation.
Use a Joined List column to gather up all the mutations
Use a Template column to prepare a JSON payload.
Send the payload to Glide, either via Make or via a Call API action.
Update:
I was thinking about this after I typed it out, and it occurred to me that it would be possible to do this with a single row Helper Table - at least for up to 500 mutations. All that would be required is to modify the JavaScript so that it returns the entire JSON payload, rather than a single mutation per row. And if more than 500 mutations are required, then it would just be a further minor tweak so that it returns 500 mutations per row, and create additional rows.
Unfortunately this method doesn’t provide editable data. In this case, to handle csv import into the table to make it scalable and editable, anyway you should add rows for each row from the table.