Export related data as CSV

This example shows you how to create a Smart Action "Export orders as CSV" that allows a user to download all the orders associated to a customer.

Requirements

How it works

Directory: /models

This directory contains:

  • the customers.js file where the customers model is declared.

  • the orders.js file where the orders model is declared

Directory: /forest

This directory contains the customers.js file where the smart action Export orders as CSV is declared.

You need to set the attribute download as true to enable a download

Directory: /utils

This directory contains a csv-exporter.js file where the method to export the orders as CSV is declared.

The json2csv package allows you to format the data exported. It can be useful in particular when you have fields of the type JSON that you may want to unwind. You can take a look at the json2csv documentation here.

Directory: /routes

This directory contains the customers.js file where the logic of the smart action is implemented.

Last updated

Was this helpful?