Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: export to csv #200

Closed
2 tasks done
Balance8 opened this issue Apr 3, 2024 · 6 comments
Closed
2 tasks done

[feat]: export to csv #200

Balance8 opened this issue Apr 3, 2024 · 6 comments

Comments

@Balance8
Copy link
Contributor

Balance8 commented Apr 3, 2024

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
@manaskshatriya
Copy link

Any Update on the feature?

@sadmann7
Copy link
Owner

sadmann7 commented Apr 8, 2024

i will try to put together a demo of it in the weekend

@manaskshatriya
Copy link

Hey any update?

@sadmann7
Copy link
Owner

sadmann7 commented Apr 20, 2024

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>

@yasseralsaidi
Copy link

can we export all filterd data without to do page by page?

@john093e
Copy link

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.
Capture-2024-04-21-184448

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.
Capture-2024-04-21-184745

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:

  1. A user on your platform requests an export.
  2. You save the export request with filters and other data in your database.
  3. You start an Inngest flow to generate the file (Papaparse can help to generate the file).
  4. Inngest streams the data in chunks to Uploadthing to ensure data is not lost and memory limits are not exceeded.
  5. 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!

@sadmann7 sadmann7 closed this as completed Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants