[feat]: export to csv
Balance8 opened this issue · 6 comments
Feature description
Add the ability to export data to csv
Additional Context
Additional details here...
Before submitting
- I've made research efforts and searched the documentation
- I've searched for existing issues and PRs
Any Update on the feature?
i will try to put together a demo of it in the weekend
Hey any update?
Thanks for suggesting the feature.
Wrote a function to export as csv.
<Button
variant="outline"
size="sm"
onClick={() =>
exportTableToCSV(table, {
filename: "tasks",
excludeColumns: ["select", "actions"],
})
}
>
<DownloadIcon className="mr-2 size-4" aria-hidden="true" />
Export
</Button>
can we export all filterd data without to do page by page?
Hello @yasseralsaidi, I will try to help on the direction to take for your request :)
Yes, it is possible to accomplish this task, but not using the CSV export feature from @sadmann7.
Why? This would involve considering many different factors. For example, imagine you have a million rows with thousands of columns and many text fields; this would result in a very large file.
1. Long-running Task:
In my opinion, this should be handled as a background job. I would use Inngest for such a task. A background job is necessary because Vercel only runs for a limited amount of time, depending on your account plan and runtime setup.
2. File Size and Memory:
Generating a CSV file as a background task requires careful memory management. Although a CSV file is typically light, it can quickly become cumbersome depending on the volume of data to be exported. For this, I would stream the data to a file saved on Uploadthing.
3. Task Concurrency:
Depending on your setup (runtime, etc.), be aware that generating a file takes time and can slow down other users' requests. Again, Inngest would be key to addressing this issue.
Final Workflow:
- A user on your platform requests an export.
- You save the export request with filters and other data in your database.
- You start an Inngest flow to generate the file (Papaparse can help to generate the file).
- Inngest streams the data in chunks to Uploadthing to ensure data is not lost and memory limits are not exceeded.
- Once the full data set is sent to your file on Uploadthing, you send a notification through your platform or by email to the user with a link to the file located on Uploadthing.
Exporting data to CSV can be quite complex!