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

react-js-table-with-csv-dl

Package Overview
Dependencies
Maintainers
1
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-js-table-with-csv-dl

React JS tables and log viewer with stats if needed. Has the functionality to dowload table contents in CSV file with data stored in class prop.

  • 0.5.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
126
increased by93.85%
Maintainers
1
Weekly downloads
 
Created
Source

npm npm npm npm

React-table-with-csv-download

React JS Table and log viewer with CSV download functionality

Description

React JS Table and log viewer with Search and CSV download functionality. You can display data table information passing JS objects and an array of dats you want to show and download the full data into a csv file. You can pick what fields of the object you want to display and download the full objects. Also you can pass a String with a JSON and will be rendered.

How to thank me? Just click on ⭐️ button :)

How it looks

alt text

Installation

Install it from npm and include it in your React build process (using Webpack, Browserify, etc).

npm i react-js-table-with-csv-dl

Usage

Import TableViewer in your react component.

import TableViewer from 'react-js-table-with-csv-dl';

Props available:

  • content - An array of objects. The key will be used for the table headers.
let table = [ 
  {number: 12, name: "Del Piero", position: "ST"},
  {number: 21, name: "Pirlo", position: "MC"},
  {number: 1, name: "Buffon", position: "GK"}
];

In the above example, will create a table with three columns: number, name, position

Optionally, you can add the key success to the object. If value is true, the row will be displayed in green, if it is false will be displayed red.

let table = [ 
  {number: 12, name: "Del Piero", position: "ST", success: true},
  {number: 21, name: "Pirlo", position: "MC", success: false},
  {number: 10, name: "Ruiz", position: "MDI"},
];

The above object will be displayed as follows:

alt text

  • headers - An array of strings with the headers you want to display

["number", "name"]

Use the same names as the object you are passing as prop. In this case, the table will show only name and number. In case of downloading data, will download the full object including the position. This gives you the ability of showing some fields and being able to download full data rows.

  • minHeight, maxHeight - Min and Max height dimensions for the table

  • activateDownloadButton - (Boolean) if you want to have a download button

For example:

<TableViewer
  title="Lineup"
  content={this.state.table}
  headers={this.state.headers}
  minHeight={0}
  maxHeight={400}
  activateDownloadButton={this.state.activateDownloadButton}
/>

You can send a JSON String to a specific cell and will be rendered correctly with different color scheme as shows in the following image:

let json = {
      "Key1": {"id":10,"values":"1-2"},
      "Key2":{},
      "Key3":"(Zone 1)",
      "description":"","array":[100],
      "array2":[],
      "Object":[{"id":1000,"values":"K-1"}]};

Note that you should convert JSON to a String using the function stringify(). Then, you'll have the result:

alt text

You can also customise the row's color (red, green or black) by sending the following row to the table with the key success:

true -> green false -> red omit the key and the text will be black by default

{ number: 12, 
  name:"Buffon", 
  position: JSON.stringify(json), 
  success: true
}

If you have big tables, you can optionally add a pagination for the table using the prop pagination.

alt text

You can also customize the style using the following props:

  • headerCss => style for headers e.g passing: {{color: "blue", backgroundColor:"#fff"}} Changes the header background to white and the text to blue

  • bodyCss => style for each row e.g passing: {{color: "blue", backgroundColor:"#fff"}} Changes the background to white and the text to blue

Props

NameTypeMandatoryDescription
contentobjectYContents to display on tables
headersarray (String)YArray of strings, these will be used to choose what to show in the table
minHeightintegerYMin table desired height
maxHeightintegerYMax table desired height
activateDownloadButtonbooleanYActivates download button
headerCssobjectNHeaders customization
bodyCssobjectNBody customizations
filenameStringNName of the downloaded filename (default is logResults.csv)
renderLineNumberpresentNrender row number at the left of the table
reverseLineNumberpresentNreverse line number to start from last (depends on reverseLineNumber)
paginationintNinteger that will indicate the max page size for the table
topPaginationbooleanNshow pagination at top of the table
pageBoxStyleobjectNcustomize style of pagination box objects
activePageBoxStyleobjectNcustomize style of active box
maxPagesToDisplayintNhow many elements will the paginator have. Default 6
downloadButtonStyleobjectNdownload button customizations
sortColumnstringNColumn that you want to sort Asc. (must be in headers prop)
placeholderSearchTextstringNPlaceholder text to appear in Searchbox
searchEnabledpresence (boolean)NActivate search feature
caseInsensitivebooleanNdo searches without casing

What's new

v0.5.5

  • Added prop feature (topPagination) to show pagination at top.

v0.5.0

  • Table now speaks JSON, you can pass as param a JSON in string format and will be rendered.

License

Licensed under the MIT License © jciccio

Keywords

FAQs

Package last updated on 07 Mar 2019

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