Coder Social home page Coder Social logo

Comments (8)

IAmNatch avatar IAmNatch commented on July 21, 2024 3

You could implement this yourself by:

  1. Creating a custom button on the collection page to trigger your export. BeforeList would probably be the right place to put it.
  2. Pulling in the data prop which is passed into your custom component by payload.
  3. Converting the object into a CSV, either manually or with a library.
  4. Trigger a download of the CSV string you've created, using something like this approach.

This should get the job done. If you wanted to go the extra mile, this would make a great payload plugin. Something like payload-plugin-csv-export, where you could select which collections you'd like to have this field added to. This would be much more general purpose, and keep the form builder plugin focused on the forms themselves.

from plugin-form-builder.

webmuch avatar webmuch commented on July 21, 2024 3

@IAmNatch That helped me so much. Thanks! I was simply able to whip this up in half an hour and replicate it across collections:

Here's my code:

yarn add xlsx

The component:

import { Pill } from "payload/components";
import React from "react";
import * as XLSX from "xlsx";

const ExportButton = ({ data }) => {
  console.log(data);
  function handleClick() {
    const worksheet = XLSX.utils.json_to_sheet(data.docs);
    const workbook = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
    XLSX.writeFile(workbook, "Data_Export.xlsx");
  }

  return (
    <Pill pillStyle="light" onClick={handleClick}>
      Export
    </Pill>
  );
};

export default ExportButton;

The Custom UI for List Page:

  admin: {
    components: {
      BeforeListTable: [ExportButton]
    },
  },

from plugin-form-builder.

Hassiad avatar Hassiad commented on July 21, 2024 2

Thanks @webmuch the solution and code snippet you provided works, also thanks to @IAmNatch for the guide

from plugin-form-builder.

leikoilja avatar leikoilja commented on July 21, 2024 1

sorry, haven't tried it just yet @IAmNatch. Thank you @webmuch for the snippet. I will give it a try soon and close this ticket if it resolves it :)

from plugin-form-builder.

IAmNatch avatar IAmNatch commented on July 21, 2024

@leikoilja does this resolve your issue?

from plugin-form-builder.

TechSynthesis avatar TechSynthesis commented on July 21, 2024

I tried this out it exports the submissions: id, formName & submissionData id. It doesn't export the contents of submissionData which is what is required. How can I get that to work?

from plugin-form-builder.

jacobsfletch avatar jacobsfletch commented on July 21, 2024

@webmuch great work 👏 This is currently planned as a Payload core feature, outlined in our public roadmap here. Feel free to leave an upvote or comment of support to prioritize that work.

from plugin-form-builder.

jacobsfletch avatar jacobsfletch commented on July 21, 2024

This plugin is now being maintained in the Packages Directory of the Payload Monorepo. This repo will soon be archived and all open issues including this one will be closed. This issue has already been added to this open discussion, though, so that it will not get lost. Please refer to that discussion for more details and to continue the conversation.

from plugin-form-builder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.