1

I am new to react-admin and I would like to have the possibility to export my CSV file to Excel.

import {FieldGuesser, ListGuesser, InputGuesser} from "@api-platform/admin";
import React from "react";
import jsonExport from 'jsonexport/dist';
import { ReferenceInput, SelectInput, Filter, downloadCSV } from 'react-admin';

const orderExporter = orders => {
  const ordersForExport = orders.map(order => {
    return {
      "Name": order.name,
      "Email": order.clientEmail,
      "Code": order.programCode,
    };
  });
  jsonExport(ordersForExport, {}, (err, csv) => {
    downloadCSV(csv, 'orders');
  });
};


export const OrderList = props => (
  <ListGuesser {...props} exporter={orderExporter} filters={<OrderFilter/>}>
    <FieldGuesser label="Statut" source={"status"}/>
    <FieldGuesser label="Name" source={"name"}/>
  </ListGuesser>
);

Do I have to create a new component with a special library? Thanks

1 Answer 1

1

I would have just made this a comment but don't have the rep on this account yet. Have you checked out the SheetJS library? https://github.com/SheetJS/sheetjs

You should be able to use this in your orderExporter function instead of the downloadCSV function. I have used it for importing files and it was relatively straightforward, but I haven't used it for exporting just yet. This demo project has an example: https://github.com/SheetJS/sheetjs/blob/master/demos/react/sheetjs.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.