New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-csv-downloader

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-csv-downloader

React csv downloader

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-25.15%
Maintainers
1
Weekly downloads
 
Created
Source

React CSV Downloader

Travis Build Status Dependency Status devDependency Status

A simple react component to allow download CSV file from js object

Installation

$ npm install --save-dev react-csv-downloader

Usage

Use with children component

import CsvDownloader from 'react-csv-downloader';

<CsvDownloader>
  <button>Download</button>
</CsvDownloader>

Use without children component

<CsvDownloader text="Download"/>

Datas

pass the downloaded datas as a component prop

const datas = [{
  cell1: 'row 1 - cell 1',
  cell2: 'row 1 - cell 2'
}, {
  cell1: 'row 2 - cell 1',
  cell2: 'row 2 - cell 2'
}];

<CsvDownloader datas={datas}/>

Column

pass the columns definition as a component prop to change the cell display name. If column isn't passed the cell display name is automatically defined with datas keys

const columns = [{
  id: 'cell1',
  displayName: 'Cell 1'
}, {
  id: 'cell2',
  displayName: 'Cell 2'
}];

<CsvDownloader columns={columns}/>

You can also use the columns definition to set the columns display order

 

Props

NameTypeDefaultRequiredDescription
bombooleantruefalseActivate or desactivate bom mode
columnsarray of objectnullfalseColumns definition
datasarray of objectnulltrueDownloaded datas
filenamestringnulltrueYou can pass the filename without extension. The extension is automatically added
separatorstring','false
noHeaderboolfalsefalseIf true the header isn't added to the csv file
prefixstring or booleanfalsefalseFilename prefix. If true prefix becomes a date in YYYYMMDDhhiiss format
suffixstring or booleanfalsefalseFilename suffix/postfix. If true suffix becomes a date in YYYYMMDDhhiiss format
textstringnullfalseDownload button text. Used if no children component.

Full example

pass the downloaded datas as a component prop

render() {
  const columns = [{
    id: 'first',
    displayName: 'First column'
  }, {
    id: 'second',
    displayName: 'Second column'
  }];

  const datas = [{
    first: 'foo',
    second: 'bar'
  }, {
    first: 'foobar',
    second: 'foobar'
  }];

  return (
    <div>
      <CsvDownloader
        filename="myfile"
        separator=";"
        columns={columns}
        datas={datas}
        text="DOWNLOAD" />
    </div>
  );
}

// content of myfile.csv
// First column;Second column
// foo;bar
// foobar;foobar

License

MIT License

Keywords

FAQs

Package last updated on 03 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc