Download CSV of all pages of paginated table?

We have a paginated table and when we click the download button it only downloads one page. Is there a fix to download the whole table?

is your table server-side paginated? (i.e. does your sql query return 10 rows at a time, or does it return all 1000 at the same time)

@abdul-nimeri server side!

ah got it! yeah so the table doesn’t quite support downloading server-side things like that (and maybe we don’t want to support that –– what if your table was actually millions of rows!)

another thing you can instead do is write a JS query to download the whole table as CSV. it would look something like this:

^there’s actually a small bug with this where it jsonifies the file instead of keeping it as CSV, but we’re fixing it! would this approach work for you @alex-godin ?

is this bug fixed

and what is the fetchWholeTable function?

yes the bug is fixed!

ah, fetchWholeTable was the name of my sql query that fetched the whole table (i.e. without any LIMIT statement)

try it out and lmk if it works for you

@abdul-nimeri can you share your fetchWholeTable again? It seems to be deleted from your reply

Hey @annaxwang -- the fetchWholeTable that Abdul referenced is just a SQL query that fetches an entire table without a limit statement (which you might have had in an original query if you were server side paginating). So if you wanted to download your users table, you might set up a query to get the whole table like:

SELECT * FROM users;

Then you'd build a Javascript query to download those results to CSV (this is kind of complicated if you need to deal with escaping characters like a comma or quote). If you call the above query getUsers you can trigger it and work with the resulting data in a Javascript query with syntax like this:

  onSuccess: function(data) {
    //Do something with data here

For some direction on how to download JSON as a CSV, there's some content in this Medium post.

1 Like

Can we add a custom action to the download data as csv button?

Hey @Osman! What kind of action are you looking to add? You can run queries from a custom button on the table!

Well I wanted to use download button to run my query but I think custom button is the only way. Okay that's fine too. Thanks

@Osman did you figure out the end-to-end solution here?

I'm looking to do the same thing - download the entire table as a CSV from a server-side paginated API.

Hey @joshdnsfilter! Would something like this work for you?

What do you currently have set up? :slight_smile: