Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
react-data-table-component
Advanced tools
The react-data-table-component package is a highly customizable and easy-to-use data table component for React applications. It provides a range of features including sorting, pagination, selectable rows, expandable rows, and custom styling.
Basic Table
This code demonstrates how to create a basic data table with sortable columns using react-data-table-component.
import DataTable from 'react-data-table-component';
const data = [{ id: 1, title: 'Conan the Barbarian', year: '1982' }, { id: 2, title: 'The Terminator', year: '1984' }];
const columns = [
{ name: 'Title', selector: row => row.title, sortable: true },
{ name: 'Year', selector: row => row.year, sortable: true }
];
<DataTable columns={columns} data={data} />;
Pagination
This code demonstrates how to enable pagination in the data table.
import DataTable from 'react-data-table-component';
const data = [...Array(100).keys()].map(i => ({ id: i, title: `Title ${i}`, year: 2000 + i }));
const columns = [
{ name: 'Title', selector: row => row.title, sortable: true },
{ name: 'Year', selector: row => row.year, sortable: true }
];
<DataTable columns={columns} data={data} pagination />;
Selectable Rows
This code demonstrates how to make rows selectable in the data table.
import DataTable from 'react-data-table-component';
const data = [{ id: 1, title: 'Conan the Barbarian', year: '1982' }, { id: 2, title: 'The Terminator', year: '1984' }];
const columns = [
{ name: 'Title', selector: row => row.title, sortable: true },
{ name: 'Year', selector: row => row.year, sortable: true }
];
<DataTable columns={columns} data={data} selectableRows />;
Expandable Rows
This code demonstrates how to add expandable rows to the data table.
import DataTable from 'react-data-table-component';
const data = [{ id: 1, title: 'Conan the Barbarian', year: '1982', description: 'A movie about a barbarian.' }, { id: 2, title: 'The Terminator', year: '1984', description: 'A movie about a terminator.' }];
const columns = [
{ name: 'Title', selector: row => row.title, sortable: true },
{ name: 'Year', selector: row => row.year, sortable: true }
];
const ExpandedComponent = ({ data }) => <pre>{JSON.stringify(data, null, 2)}</pre>;
<DataTable columns={columns} data={data} expandableRows expandableRowsComponent={ExpandedComponent} />;
Custom Styling
This code demonstrates how to apply custom styles to the data table.
import DataTable from 'react-data-table-component';
const data = [{ id: 1, title: 'Conan the Barbarian', year: '1982' }, { id: 2, title: 'The Terminator', year: '1984' }];
const columns = [
{ name: 'Title', selector: row => row.title, sortable: true },
{ name: 'Year', selector: row => row.year, sortable: true }
];
const customStyles = {
rows: {
style: {
minHeight: '72px', // override the row height
},
},
headCells: {
style: {
paddingLeft: '8px', // override the cell padding for head cells
paddingRight: '8px',
},
},
cells: {
style: {
paddingLeft: '8px', // override the cell padding for data cells
paddingRight: '8px',
},
},
};
<DataTable columns={columns} data={data} customStyles={customStyles} />;
react-table is a lightweight, fast, and extendable data grid built for React. It provides a hook-based API and is highly customizable. Compared to react-data-table-component, react-table offers more flexibility and control over the table's behavior and appearance, but it requires more setup and configuration.
material-table is a data table component built on top of Material-UI. It provides a rich set of features out of the box, including sorting, filtering, pagination, and inline editing. Compared to react-data-table-component, material-table offers a more integrated experience with Material-UI and additional features like inline editing, but it may be heavier due to its dependency on Material-UI.
ag-grid-react is a feature-rich data grid component for React applications. It offers a wide range of features including sorting, filtering, pagination, and complex data manipulation. Compared to react-data-table-component, ag-grid-react is more powerful and suitable for complex use cases, but it has a steeper learning curve and may be overkill for simpler applications.
Creating yet another React table library came out of necessity while developing a web application for a growing startup. I discovered that while there are some great table libraries out there, some required heavy customization, were missing out of the box features such as built in sorting and pagination, or required understanding the atomic structure of html tables.
If you want to achieve balance with the force and want a simple but flexible table library give React Data Table Component a chance. If you require an Excel clone, then this is not the React table library you are looking for 👋
The documentation contains information about installation, usage and contributions.
https://react-data-table-component.netlify.app
If you would like to support the project financially, visit our campaign on OpenCollective. Your contributions help accelerate the development of React Data Table Component!
FAQs
A simple to use declarative react based data table
The npm package react-data-table-component receives a total of 134,231 weekly downloads. As such, react-data-table-component popularity was classified as popular.
We found that react-data-table-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.